-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecial Prime.java
More file actions
51 lines (45 loc) · 1.18 KB
/
Special Prime.java
File metadata and controls
51 lines (45 loc) · 1.18 KB
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
47
48
49
50
51
import java.util.Scanner;
import java.util.Arrays;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
boolean[] b=new boolean[n];
ss(b);
n--;
while(true){
if(check(b,n)==true)
{
System.out.println(n);
return;
}
else
{
n--;
}
}
}
public static void ss(boolean b[])
{
Arrays.fill(b,true);
b[0]=false;
b[1]=false;
for(int i=2;i<=Math.sqrt(b.length);i++){
if(b[i]==true)
{
for(int j=i*i;j<b.length;j=j+i)
b[j]=false;
}
}
}
public static boolean check(boolean b[],int n){
while(n!=0){
if(b[n]==false)
return false;
n/=10;
}
return true;
}
}