Cod sursa(job #897511)

Utilizator thewildnathNathan Wildenberg thewildnath Data 27 februarie 2013 21:02:31
Problema Divizori Primi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<stdio.h>
int c[1000010],div[8][1000001];
void ciur()
{
    int i,j,lim;
    c[2]=1;
    for(i=4;i<=1000000;i=i+2)
        c[i]++;
    for(i=3;i<=1000000;i=i+2)
        if(c[i]==0)
            for(j=i;j<=1000000;j=j+i)
                ++c[j];
}
int main()
{
    freopen("divprim.in","r",stdin);
    freopen("divprim.out","w",stdout);
    int n,k,i,j,t;
    scanf("%d",&t);
    ciur();
    for(i=1;i<=7;i++)
        for(j=1;j<=1000000;j++)
            if(c[j]==i)
                div[i][j]=j;
            else
                div[i][j]=div[i][j-1];
    for(i=1;i<=1000000;i++)
        div[0][i]=1;
    while(t)
    {
        t--;
        scanf("%d%d",&n,&k);
        printf("%d\n",div[k][n]);

    }
    return 0;
}