-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10533.cpp
73 lines (71 loc) · 1.1 KB
/
10533.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
#include <cstdio>
#include <math.h>
int a[1000001];
int check(int n)
{
int m,i;
if(n==0)
return 0;
if(n==1)
return 0;
if(n==2)
return 1;
if(n%2==0)
return 0;
for(i=3;i*i<=n;i+=2)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
main()
{
int i,j,n,t,t1,t2,count;
a[0]=0;
for(i=1;i<=1000000;i++)
{
if(i%2==0 && i!=2)
{
a[i]=a[i-1]+0;
}
else if(check(i)==1)
{
n=0;
j=i;
while(j>0)
{
n+=j%10;
j=j/10;
}
if(check(n)==1)
{
a[i]=a[i-1]+1;
}
else
{
a[i]=a[i-1]+0;
}
}
else
{
a[i]=a[i-1]+0;
}
}
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&t1,&t2);
if(t1>t2)
{
i=t1;
t1=t2;
t2=i;
}
count=a[t2]-a[t1-1];
printf("%d\n",count);
}
return 0;
}