fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4.  
  5. bool check_prime(int n){
  6. if(n < 2) return false;
  7. for(int i = 2; i*i <= n; i++){
  8. if(n % i == 0) return false;
  9. }
  10. return true;
  11. }
  12. signed main(){
  13.  
  14. queue<int> q;
  15. q.push(2);
  16. q.push(3);
  17. q.push(5);
  18. q.push(7);
  19.  
  20. vector<int> a;
  21. while(!q.empty()){
  22. int x = q.front();
  23. // a.push_back(x);
  24. q.pop();
  25. if(x >=1e13-1){
  26. // cout << x << "\n";
  27. continue;
  28. }
  29. else{
  30. int newx = x*10;
  31. for(int i = 1; i <= 9; i+=2){
  32. if(check_prime(newx + i)){
  33. a.push_back(newx + i);
  34. // cout << "as";
  35. q.push(newx + i);
  36. }
  37. }
  38. }
  39.  
  40. }
  41. int x,y;
  42. cin >> x >> y;
  43. sort(a.begin(), a.end());
  44. auto it1 = lower_bound(a.begin(), a.end(), x);
  45. auto it2 = upper_bound(a.begin(), a.end(), y);
  46. int ans = max(0LL, (int)(it2 - it1));
  47. cout << ans;
  48. // for(int i : a){
  49. // cout << i << " ";
  50. // }
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty