Skip to content

Commit f5b1764

Browse files
Merge pull request PrajaktaSathe#156 from KB786/main
Mersenne Prime
2 parents e1664b0 + e32cd1e commit f5b1764

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ It is very easy to contribute, you may follow these steps -
126126
99.[RotateLinkedList](https://github.com/PrajaktaSathe/Java/blob/main/Programs/RotateLinkedList.java)-Program to demo rotating a linked list
127127
100. [ReverseString](https://github.com/PrajaktaSathe/Java/blob/main/ReverseString.java) -Program to reverse a String using the java method substring.
128128
101.[Overriding](https://github.com/PrajaktaSathe/Java/blob/main/Programs/Overriding.java)-Program to demo overriding in java
129+
129130
# Contributors -
130131
## A big thank you to all our contributors!!!
131132

mersenneprime.java

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

0 commit comments

Comments
 (0)