+ 3

A way to find very large prime numbers?

Algorythms and, if possible, code needed!

10th Sep 2019, 10:32 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
4 Respuestas
+ 1
just change the range in the for in the main to your range of numbers. code in Java: package test; public class gfhugdsau { public static void isprime(int num){ boolean flag = false; for(int i = 2; i <= num/2;i++) { if(num==i){ continue; } if(num % i == 0) { flag = true; break; } } if (!flag){ System.out.println(num + " is a prime number."); } } public static void main(String[] args) { for(int i=1000;i<100000;i++){ isprime(i); } } }
10th Sep 2019, 10:54 AM
KfirWe
KfirWe - avatar
+ 1
Ehr.... I meant, prime numbers with thousands of digits
10th Sep 2019, 10:58 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 1
@Paolo De Nictolis java will give you a error for this type of number.. unfortuntly, java can't handle with number with more than 10 digits. this is the best we can do : package test; public class gfhugdsau { public static void isprime(long num){ boolean flag = false; for(int i = 2; i <= num/2;i++) { if(num==i){ continue; } if(num % i == 0) { flag = true; break; } } if (!flag){ System.out.println(num + " is a prime number."); }else{ System.out.println("efew"); } } public static void main(String[] args) { String str="1"; for(int j=0;j<9;j++){ str = str+"0"; } long x=Integer.valueOf(str); for(long i=x;i<x+100000;i++){ isprime(i); } } }
10th Sep 2019, 11:28 AM
KfirWe
KfirWe - avatar
0
Consider this, Paolo De Nictolis. The largest possible datatype for *positive* numbers is ulong and even *that* can only hold 20 digits To get any bigger you will need a system akin to a long-adder
10th Sep 2019, 1:01 PM
Trigger
Trigger - avatar