Cod sursa(job #2713246)

Utilizator PatruMihaiPatru Mihai PatruMihai Data 27 februarie 2021 15:42:50
Problema Divizori Primi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("divprim.in");
ofstream fout("divprim.out");

const int nmax = 1e6;

int nrdiv[nmax + 1];
int dp[nmax + 1][8];

void ciur()
{
    for(int i = 2; i <= nmax; i++)
    {
        if(nrdiv[i] == 0)
        {
            for(int j = i; j <= nmax; j += i)
            {
                nrdiv[j]++;
            }
        }
    }
}


int main()
{
    int t;
    fin >> t;

    ciur();

    for(int i = 2; i <= nmax; i++)
    {
        for(int j = 1; j <= 7; j ++)
        {
            dp[i][j] = dp[i - 1][j];
        }
        dp[i][nrdiv[i]] = i;
    }

    while(t--)
    {
        int n, k;
        fin >> n >> k;

        fout << dp[n][k] << "\n";

    }
    return 0;
}