Cod sursa(job #1453432)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 23 iunie 2015 15:13:52
Problema Divizori Primi Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;
ifstream in("divprim.in");
ofstream out("divprim.out");
const int maxn=1000005;
int ciur[maxn];
int main()
{
    for(int i=2;i<maxn;i++)
        ciur[i]=1;
    for(int i=2;i<=maxn;i++)
        if(ciur[i]==1)
            for(int j=1;1LL*i*j<=maxn;j++)
                ciur[i*j]++;
    for(int i=2;i<maxn;i++)
            ciur[i]--;
    int T;
    in>>T;
    for(int l=1;l<=T;l++)
    {
        int n,k;
        in>>n>>k;
        if(n==0)
            out<<0<<"\n";
        else if(k==0 && n>=1)
            out<<1<<"\n";
        else
        {
            int i=n;
            while(i>=1)
            {
                if(ciur[i]==k)
                {
                    out<<i<<"\n";
                    break;
                }
                i--;
            }
            if(i==0 && ciur[i]!=k)
                out<<0<<"\n";
        }
    }
    return 0;
}