-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCP01003.cpp
57 lines (55 loc) · 956 Bytes
/
CP01003.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
#include<iostream>
#include<math.h>
using namespace std;
bool isSnt(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
bool isTnt(int n){
if(!isSnt(n)){
return 0;
}
int sum=0;
int d=n;
while(d>0){
int tmp=d%10;
sum+=tmp;
if(!isSnt(tmp)){
return 0;
}
d=d/10;
}
if(!isSnt(sum)){
return 0;
}
return 1;
}
int main(){
int t=0;
cin>>t;
while(t--){
int a,b;
cin>>a>>b;
int c=0;
for(int i=a;i<=b;i++){
if(isTnt(i)){
c+=1;
}
}
cout<<c<<endl;
}
}
/**
* @brief
* https://www.geeksforgeeks.org/c-program-to-check-prime-number/
*
*/