-
Notifications
You must be signed in to change notification settings - Fork 0
/
Number99.java
61 lines (60 loc) · 1.33 KB
/
Number99.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.*;
public class Number99 {
public static void main(String[] args) {
int n=100000;
Prime(n);
}
static int Rotate(long n)
{
long r=n%10;
r*=Math.pow(10,count(n));
n /= 10;
n+=r;
return (int) n;
}
static void Prime(long n)
{
long b=(n-2)/2;
boolean m[]=new boolean[(int)(b + 1)];
Arrays.fill(m,false);
store(m,b);
System.out.print("2 ");
for (long i=1;i<=b;i++)
{
if (m[(int) i] == true)
continue;
long a=2*i+1;
a=Rotate(a);
while (a!=2*i+1)
{
if (a%2==0)
break;
if (m[(int)((a-1)/2)]==false)
a= Rotate(a);
else
break;
}
if (a==((2*i)+1))
System.out.print(a+" ");
}
}
static int count(long n)
{
long d=0;
while ((n/=10)>0)
{
d++;
}
return (int)d;
}
static void store(boolean marked[],long n)
{
for (long i=1;i<=n;i++)
{
for (long j=i;(i+j+(2*i*j))<=n;j++)
{
marked[(int)(i+j+(2*i*j))] = true;
}
}
}
}