fork download
  1. #include <iostream>
  2. #include<cmath>
  3. using namespace std;
  4. #define in() getchar_unlocked()
  5. int fi()
  6. {
  7. int num=0;
  8. while(1)
  9. {
  10. char x=in();
  11. if(x-'0'>9||x-'0'<0)
  12. break;
  13. else
  14. num=(num<<3+num<<1+(x-'0'));
  15. }
  16. return num;
  17. }
  18. int getsum(int x)
  19. {
  20. int sum=0;
  21. while(x!=0)
  22. {
  23. int temp=x%10;
  24. sum+=temp;
  25. x/=10;
  26. }
  27. return sum;
  28. }
  29. bool checkprime(int y)
  30. {
  31. for(int i=2;i<=sqrt(y);i++)
  32. {
  33. if(!(y%i))
  34. return 0;
  35. }
  36. return 1;
  37. }
  38.  
  39. int main() {
  40. // your code goes here
  41. int t;
  42. cin>>t;
  43. while(t--)
  44. {
  45. int ll,ul,count=0;
  46. cin>>ll>>ul;
  47. for(int i=ll;i<=ul;i++)
  48. {
  49. int x=getsum(i);
  50. if(x==2)
  51. count++;
  52. else if((x&1)&&(x>2))
  53. {
  54. if(checkprime(x))
  55. count++;
  56. }
  57. }
  58. cout<<count<<"\n";
  59.  
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0s 3100KB
stdin
3
11
21
3
11
10
20
stdout
6
4
5