Advertisement
Guest User

dziala lol

a guest
May 20th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. std::queue<long long> q;
  5. long long num[4] = {1, 3, 7, 9};
  6.  
  7. bool check(long long x) {
  8.     if (x == 1 || x == 0)
  9.         return false;
  10.     for (long long i = 2; i * i <= x; i++) {
  11.         if (x % i == 0)
  12.             return false;
  13.     }
  14.     return true;
  15. }
  16.  
  17. int main() {
  18.     long long min, max;
  19.     scanf("%lld%lld", &min, &max);
  20.     q.push(2);
  21.     q.push(3);
  22.     q.push(5);
  23.     q.push(7);
  24.     long long ile = 0;
  25.     while (!q.empty()) {
  26.         if (min <= q.front() && q.front() <= max)
  27.             ile++;
  28.         for (auto it : num) {
  29.             if (q.front() * 10 + it <= max && check(q.front() * 10 + it))
  30.                 q.push(q.front() * 10 + it);
  31.         }
  32.         q.pop();
  33.     }
  34.     printf("%lld", ile);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement