Advertisement
erfanul007

UVa 10533

Jan 23rd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scl(n) scanf("%lld",&n)
  17. #define scf(n) scanf("%lf",&n)
  18. #define scs(s) scanf("%s",s)
  19. #define pfi(n) printf("%d",n)
  20. #define pfl(n) printf("%lld",n)
  21. #define pff(n) cout<<n
  22. #define line printf("\n")
  23. #define spc printf(" ")
  24. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  25. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  26. #define cspf(i) printf("Case %d: ", i)
  27. #define pb push_back
  28. #define mp make_pair
  29. #define ff first
  30. #define ss second
  31. #define all(v) v.begin(),v.end()
  32. #define rall(v) v.rbegin(),v.rend()
  33. #define read() freopen("input.txt", "r", stdin)
  34. #define write() freopen("output.txt", "w", stdout)
  35. /// Constants
  36. #define eps 1e-9
  37. #define PI acos(-1.0) // 3.1415926535897932
  38.  
  39. vi chk(1000009);
  40. vi cnt(1000009);
  41.  
  42.  
  43. void seive(){
  44. chk[0]=1;
  45. chk[1]=1;
  46. for(int i=2;i<=1000001;i++){
  47. if(chk[i]==1)
  48. continue;
  49. for(int j=2;i*j<=1000001;j++){
  50. chk[i*j]=1;
  51. }
  52. }
  53. }
  54.  
  55. int sum(int i)
  56. {
  57. int sm=0;
  58. while(i>0){
  59. sm+=(i%10);
  60. i/=10;
  61. }
  62. return sm;
  63. }
  64.  
  65. void prec()
  66. {
  67. int c=0;
  68. loop(i,0,1000001){
  69. if(chk[i]==0){
  70. int dgsm=sum(i);
  71. if(chk[dgsm]==0){
  72. c++;
  73. }
  74. }
  75. cnt[i]=c;
  76. }
  77. }
  78.  
  79. int main()
  80. {
  81. seive();
  82. prec();
  83. int t;sci(t);
  84. int pcnt;
  85. loop(i,1,t){
  86. int x,y;
  87. sci(x);sci(y);
  88. if(x==0){
  89. pcnt=cnt[y];
  90. }
  91. else{
  92. pcnt=cnt[y]-cnt[x-1];
  93. }
  94. pfi(pcnt);line;
  95. }
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement