Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <cstdio>
- #include <queue>
- #include <vector>
- #define task "SPRIME"
- using namespace std;
- using ll = unsigned long long;
- using ld = long double;
- const int N = 1e5 + 2;
- ll l, r;
- vector<ll> a;
- void ReadInput()
- {
- cin >> l >> r;
- }
- bool Check(ll v){
- if(v < 2)
- return 0;
- if(v % 2 == 0)
- return v == 2;
- for(ll i = 3; i * i <= v; i += 2)
- if(v % i == 0)
- return false;
- return true;
- }
- ll Pow(ll v){
- ll ans = 1;
- while(v){
- ans *= 10ll;
- v /= 10ll;
- }
- return ans;
- }
- ll make(ll c, ll i){
- return i * Pow(c) + c;
- }
- void Gen(){
- queue<ll> s;
- s.push(2); a.push_back(2);
- s.push(3); a.push_back(3);
- s.push(5); a.push_back(5);
- s.push(7); a.push_back(7);
- while(s.size()){
- ll c = s.front();
- s.pop();
- for(int i = 1; i < 10; ++i){
- ll v = make(c, i);
- if(v <= r && Check(v)){
- s.push(v);
- a.push_back(v);
- }
- }
- }
- }
- void trau(){
- int cnt = 0;
- ll ls = l;
- while(l <= r){
- ll c = Pow(l) / 10, v = l;
- while(v){
- if(!Check(v))
- goto ABCDEF;
- v %= c;
- c /= 10;
- if(v < c)
- goto ABCDEF;
- }
- ++cnt;
- // << l << " ";
- ABCDEF:;
- ++l;
- }
- l = ls;
- cout << "\n" << cnt << "\n";
- }
- void Solve()
- {
- Gen();
- sort(a.begin(), a.end());
- //trau();
- //for(auto i : a)
- // cout << i << " ";
- //cout << "\n";
- cout << (upper_bound(a.begin(), a.end(), r) - lower_bound(a.begin(), a.end(), l) );
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- if(fopen(task".INP", "r"))
- freopen(task".INP", "r", stdin),
- freopen(task".OUT", "w", stdout);
- ReadInput();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment