fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define endl "\n"
  4. #define F first
  5. #define S second
  6. #define loop(a,n) for(int i=a; i<=n ; i++)
  7. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  8. #define NAME "sieungto"
  9. using namespace std;
  10. ll a, b, res;
  11. bool check(ll n) {
  12. if (n < 2) return false;
  13. if (n == 2 || n == 3) return true;
  14. if (n % 2 == 0) return false;
  15. for (ll i = 3; i * i <= n; i += 2)
  16. if (n % i == 0) return false;
  17. return true;
  18. }
  19.  
  20. ll solve(ll a, ll b) {
  21. queue<ll> q;
  22. q.push(2); q.push(3); q.push(5); q.push(7);
  23. ll d = 0;
  24. while (!q.empty()) {
  25. ll h = q.front();
  26. q.pop();
  27. if (h >= a && h <= b)
  28. d++;
  29. if (h > b / 10) continue;
  30. int dg[] = {1, 3, 7, 9};
  31. for (int i = 0; i < 4; i++) {
  32. ll next = h * 10 + dg[i];
  33. if (check(next)) {
  34. q.push(next);
  35. }
  36. }
  37. }
  38. return d;
  39. }
  40. int main() {
  41. ios_base::sync_with_stdio(0);
  42. cin.tie(0); cout.tie(0);
  43. freopen(NAME".INP", "r", stdin);
  44. freopen(NAME".OUT", "w", stdout);
  45. while (cin >> a >> b) {
  46. res += solve(a, b);
  47. }
  48.  
  49. cout << res;
  50. //cout << "Time: " << TIME << "s\n";
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5320KB
stdin
2000 7500
50 100
200 300
stdout
Standard output is empty