Dang_Quan_10_Tin

Untitled

Jun 24th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <queue>
  5. #include <vector>
  6. #define task "SPRIME"
  7.  
  8. using namespace std;
  9. using ll = unsigned long long;
  10. using ld = long double;
  11.  
  12. const int N = 1e5 + 2;
  13.  
  14. ll l, r;
  15. vector<ll> a;
  16.  
  17. void ReadInput()
  18. {
  19.     cin >> l >> r;
  20. }
  21.  
  22. bool Check(ll v){
  23.     if(v < 2)
  24.         return 0;
  25.     if(v % 2 == 0)
  26.         return v == 2;
  27.     for(ll i = 3; i * i <= v; i += 2)
  28.         if(v % i == 0)
  29.             return false;
  30.     return true;
  31. }
  32.  
  33. ll Pow(ll v){
  34.     ll ans = 1;
  35.     while(v){
  36.         ans *= 10ll;
  37.         v /= 10ll;
  38.     }
  39.     return ans;
  40. }
  41.  
  42. ll make(ll c, ll i){
  43.     return i * Pow(c) + c;
  44. }
  45.  
  46. void Gen(){
  47.     queue<ll> s;
  48.     s.push(2); a.push_back(2);
  49.     s.push(3); a.push_back(3);
  50.     s.push(5); a.push_back(5);
  51.     s.push(7); a.push_back(7);
  52.     while(s.size()){
  53.         ll c = s.front();
  54.         s.pop();
  55.         for(int i = 1; i < 10; ++i){
  56.             ll  v = make(c, i);
  57.             if(v <= r && Check(v)){
  58.                 s.push(v);
  59.                 a.push_back(v);
  60.             }
  61.         }
  62.     }
  63. }
  64.  
  65. void trau(){
  66.     int cnt = 0;
  67.     ll ls = l;
  68.     while(l <= r){
  69.         ll c = Pow(l) / 10, v = l;
  70.         while(v){
  71.             if(!Check(v))
  72.                 goto ABCDEF;
  73.             v %= c;
  74.             c /= 10;
  75.             if(v < c)
  76.                 goto ABCDEF;
  77.         }
  78.         ++cnt;
  79.         // << l << " ";
  80.         ABCDEF:;
  81.         ++l;
  82.     }
  83.     l = ls;
  84.     cout << "\n" << cnt << "\n";
  85. }
  86.  
  87. void Solve()
  88. {
  89.     Gen();
  90.     sort(a.begin(), a.end());
  91.     //trau();
  92.     //for(auto i : a)
  93.     //    cout << i << " ";
  94.     //cout << "\n";
  95.     cout << (upper_bound(a.begin(), a.end(), r) - lower_bound(a.begin(), a.end(), l) );
  96. }
  97.  
  98. int main()
  99. {
  100.     ios_base::sync_with_stdio(false);
  101.     cin.tie(nullptr);
  102.     if(fopen(task".INP", "r"))
  103.         freopen(task".INP", "r", stdin),
  104.         freopen(task".OUT", "w", stdout);
  105.     ReadInput();
  106.     Solve();
  107. }
Advertisement
Add Comment
Please, Sign In to add comment