Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
jb12.0 threads.enums
2B
Java - Swap two numbers without using temp var
linear search
Java
Assignment for Web Software Developer position
Fibonacci number 0 - 93
String reverse
Combination Sum (Leetcode)
LinearSearch
Please log in to post a comment.