In this HackerEarth Special numbers problem solution, A natural number is special if it consists of only digits 4 and 7. Find the number of pairs of —Āoprime special numbers (x, y) such that 1 <= x <= y <= N.


HackerEarth Special numbers problem solution


HackerEarth Special numbers problem solution.

#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> g;

void f(long long v) {
        if (v > n) return;
        if (v > 0) g.push_back(v);
        f(10*v + 4);
        f(10*v + 7);
}

int main() {
        cin >> n;
        f(0);
        int result = 0;
        for (int i = 0; i < (int)g.size(); ++i)
                for (int j = i + 1; j < (int)g.size(); ++j)
                        if (__gcd(g[i], g[j]) == 1)
                                ++result;
        cout << result << '\n';
        return 0;
}