Sort by

recency

|

11 Discussions

|

  • + 0 comments

    Hailey Treasure Adventure All Unlocked invites players to embark on a thrilling quest with Hailey as she searches for lost treasures across exotic locations. Experience the excitement of uncovering secrets and solving intricate puzzles in this captivating adventure.

  • + 0 comments

    Overall, choosing the right car transport service is crucial to ensuring that your car arrives safely and on time. With so many options available, it's important to do your research and choose a reputable provider with competitive rates. By doing so, you can enjoy peace of mind and save money in the process. Car Transport Rates Hopewell, Virginia

  • + 0 comments

    No matter the type of content you choose, there are a few key elements to keep in mind. First and foremost, make sure your content is well-researched and accurate. Quality content should be informative, interesting, and offer valuable insights. It should also be easy to read and understand. https://perfecttv4you.com/best-32-inch-tv-for-pc-monitor/

  • + 0 comments

    Hello, thanks for sharing its solution with us. It is really very helpful for me and I am very happy I found your post. When I was searching for your post online on google search, I found https://letsgradeit.com/review/writepaperforme/ website link and it makes me so happy because I always face problems in choosing the best essay writing service.

  • + 0 comments
    #include <bits/stdc++.h>
    
    inline bool hasPrimeDigitsOnly(long long n) {
        while (n > 0) {
            int d = int(n % 10);
            if (d != 2 && d != 3 && d != 5 && d != 7) {
                return false;
            }
            n /= 10;
        }
        return true;
    }
    
    std::vector<int> getPrimesTill(int max) {
        assert(max >= 1);
        std::vector<int> primes;
        std::vector<bool> isPrime(1 + max, true);
        isPrime[0] = false;
        isPrime[1] = false;
        for (int i = 2; i * i <= max; i++) {
            if (isPrime[i]) {
                for (int j = i * i; j <= max; j += i) {
                    isPrime[j] = false;
                }
            }
        }
        for (int i = 2; i < (int)isPrime.size(); i++) {
            if (isPrime[i]) {
                primes.push_back(i);
            }
        }
        return primes;
    }
    
    const int MAX_ROOT = (int)std::sqrt(1e15);
    
    int countMegaPrimes(long long first, long long last) {
        assert(1 <= first && last <= (long long)MAX_ROOT * MAX_ROOT);
        if (first > last) {
            return 0;
        }
        static std::vector<int> primes = getPrimesTill(MAX_ROOT);
        std::vector<bool> isPrime(last - first + 1, true); // isPrime[i] <-> (i + first) is prime
        for (int p : primes) {
            long long p2 = 1LL * p * p;
            if (p2 > last) {
                break;
            }
            long long from = std::max(1LL * p, (first + p - 1) / p) * p;
            assert(from >= first);
            int fromShifted = (int)(from - first);
            int lastShifted = (int)(last - first);
            for (int i = fromShifted; i <= lastShifted; i += p) {
                isPrime[i] = false;
            }
        }
        int count = 0;
        for (int i = 0; i < (int)isPrime.size(); i++) {
            if (isPrime[i] && hasPrimeDigitsOnly(i + first)) {
                count++;
            }
        }
        return count;
    }
    
    int main() {
        long long first, last;
        scanf("%lld %lld", &first, &last);
        const int CHUNK = 10 * 1000 * 1000;
        const int CHUNK_FIRST = 2222222; // 7 digits
        const int CHUNK_LAST = 7777777; // 7 digits
        const int LAST_BEFORE_CHUNK = 777777; // 6 digits
        long long count = 0;
        if (last <= LAST_BEFORE_CHUNK) {
            count = countMegaPrimes(first, last);
        } else {
            assert(last > LAST_BEFORE_CHUNK);
            if (first <= LAST_BEFORE_CHUNK) {
                count = countMegaPrimes(first, LAST_BEFORE_CHUNK);
                first = LAST_BEFORE_CHUNK + 1;
            }
            assert(first <= last);
            for (long long partFirst = first / CHUNK * CHUNK + CHUNK_FIRST; partFirst <= last; partFirst += CHUNK) {
                if (hasPrimeDigitsOnly(partFirst)) {
                    long long partLast = partFirst - CHUNK_FIRST + CHUNK_LAST;
                    count += countMegaPrimes(std::max(first, partFirst), std::min(last, partLast));
                }
            }
        }
        printf("%lld", count);
        return 0;
    }