Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Largest prime factor
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_72 import java.util.*; import java.lang.*; import java.math.BigInteger; import java.util.ArrayList; class Rextester { public static void main(String args[]) { BigInteger test = new BigInteger("211"); ArrayList<String> list = new ArrayList<>(); list = calc(test); String res = ""; for(int i = 0; i < list.size(); i++){ res += list.get(i)+", "; } System.out.println(res); } public static Boolean isPrime(BigInteger a) { BigInteger b = new BigInteger("2"); BigInteger c = new BigInteger("1"); BigInteger d = new BigInteger("0"); int res = 5; if(a.mod(b).compareTo(a) == 0) { return false; } b.add(c); //3 if(a.mod(b).compareTo(a) == 0) { return false; } b.add(c); b.add(c); //5 if(a.mod(b).compareTo(a) == 0) { return false; } b.add(c); b.add(c); //7 if(a.mod(b).compareTo(a) == 0) { return false; } b.add(c); b.add(c); b.add(c); b.add(c); //11 return true; } public static ArrayList<String> calc(BigInteger a) { ArrayList<String> list = new ArrayList<>(); list.add("(Values)"); BigInteger count = new BigInteger("1"); BigInteger c = new BigInteger("1"); BigInteger d = new BigInteger("0"); while (a.compareTo(count) == -1) { System.out.println("Made it"); if(isPrime(count)) { if (a.mod(count).compareTo(d) == 0) {list.add(a.toString()); } } count.add(c); } return list; } }
run
|
edit
|
history
|
help
0
Draw rectangle using for loop
assigment java programming
bookstore
LRU cache - Using doubly linked list (Fast!)
++a vs a++ and calculations around different variables
calc exp nha
Java Q4
pow x^n
Combination Sum (Leetcode)
Document management system - build unordered list (table of contents) recursively