Cod sursa(job #2798192)

Utilizator UnknownPercentageBuca Mihnea-Vicentiu UnknownPercentage Data 10 noiembrie 2021 23:48:04
Problema Divizori Primi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>

using namespace std;

inline void Open(const string Name) {
    #ifndef ONLINE_JUDGE
        (void)!freopen((Name + ".in").c_str(), "r", stdin);
        (void)!freopen((Name + ".out").c_str(), "w", stdout);
    #endif
}

int dp[1000001][8];
int cnt[1000001];

void sieve() {
    for(int i = 2;i <= 1000000;i++)
        if(cnt[i] == 0) {
            for(int j = i;j <= 1000000;j += i)
                cnt[j]++;
        }

    for(int i = 2;i <= 1000000;i++) {
        for(int k = 1;k <= 7;k++)
            dp[i][k] = dp[i - 1][k];
        dp[i][cnt[i]] = i;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    Open("divprim");

    sieve();

    int T; cin >> T;

    while(T--) {
        int N, K; cin >> N >> K;
        cout << dp[N][K] << "\n";
    }

    return 0;
}