-
Notifications
You must be signed in to change notification settings - Fork 92
/
mersenneprime.java
46 lines (40 loc) · 1.04 KB
/
mersenneprime.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//To find mersenne's prime upto
import java.util.*;
import java.lang.*;
public class mersenneprime {
public static boolean isPrime(long n){
boolean isPrime =true;
for(int j=2;j<n;j++){
if(n%j==0 || n==1 || n==0){
isPrime=false;
break;
}else{
isPrime=true;
}
}
return isPrime;
}
public static void main(String[] args) {
Scanner scr = new Scanner(System.in);
System.out.println("Enter the range:");
long p= scr.nextLong();
List<Long>twoindexlist=new ArrayList<Long>();
long two=2;
for(int k=1;k<100;k++){
two*=2;
twoindexlist.add(two);
if(two>=p){
break;
}
}
for (Long long1 : twoindexlist) {
System.out.println(long1);
}
/*
for(long i=0; i<p;i++){
if(isPrime(i)==true && twoindexlist.contains(i+1)==true){
System.out.println(i);
}
}*/
}
}