Advertisement
Farjana_akter

Untitled

Feb 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool mark[1000009]={false};
  5. int isprime[1000009];
  6. void sieve()
  7. {
  8. int i,j,k=0;
  9. mark[0]=true;
  10. mark[1]=true;
  11. for(i=2;i*i<=1000000;i++)
  12. {
  13. if(mark[i]==false)
  14. {
  15. for(j=i*i;j<=1000000;j+=i)
  16. {
  17. mark[j]=true;
  18. }
  19. }
  20. }
  21. }
  22. void prime()
  23. {
  24.  
  25. int i,j,a,k,sum=0,count=0;
  26. for(i=2;i<=1000000;i++)
  27. {
  28. if(mark[i]==false)
  29. {
  30. a=i;
  31. sum=0;
  32. while(a>0)
  33. {
  34. sum+=(a%10);
  35. a/10;
  36. }
  37. if(mark[sum]==false)
  38. count++;
  39. }
  40. isprime[i]=count;
  41. }
  42. }
  43. int main()
  44. {
  45. sieve();
  46. prime();
  47. int a,t,b,c,i,j=0;
  48. scanf("%d",&t);
  49. for(i=1;i<=t;i++)
  50. {
  51. scanf("%d %d",&a,&b);
  52. c=isprime[b]-isprime[a-1];
  53. printf("%d\n",c);
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement