Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- std::queue<long long> q;
- long long num[4] = {1, 3, 7, 9};
- bool check(long long x) {
- if (x == 1 || x == 0)
- return false;
- for (long long i = 2; i * i <= x; i++) {
- if (x % i == 0)
- return false;
- }
- return true;
- }
- int main() {
- long long min, max;
- scanf("%lld%lld", &min, &max);
- q.push(2);
- q.push(3);
- q.push(5);
- q.push(7);
- long long ile = 0;
- while (!q.empty()) {
- if (min <= q.front() && q.front() <= max)
- ile++;
- for (auto it : num) {
- if (q.front() * 10 + it <= max && check(q.front() * 10 + it))
- q.push(q.front() * 10 + it);
- }
- q.pop();
- }
- printf("%lld", ile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement