Cod sursa(job #1549672)

Utilizator PopoviciRobertPopovici Robert PopoviciRobert Data 12 decembrie 2015 17:08:59
Problema GFact Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <cstdio>
#define SQRT 100000
int exp[SQRT+1];
inline int cauta(int n){
    int flag=1,d=2,con;
    long long p;
    while(d<=SQRT&&d<=n&&flag){
        con=0;
        p=d;
        while(p<=n){
            con=con+n/p;
            p=p*d;
        }
        if(con<exp[d])
              flag=0;
        d++;
    }
    return flag;
}
int main(){
    FILE*fi,*fout;
    int a,b,d,e,rez,pas;
    fi=fopen("gfact.in" ,"r");
    fout=fopen("gfact.out" ,"w");
    fscanf(fi,"%d%d" ,&a,&b);
    d=2;
    while(d*d<=a){
        e=0;
        while(a%d==0){
            a/=d;
            e++;
        }
        exp[d]=e*b;
        d++;
    }
    if(a>1)
          exp[a]=b;
    rez=0;
    for(pas=1<<20;pas;pas>>=1)
        if(cauta(rez+pas)==0)
           rez+=pas;
    fprintf(fout,"%d" ,rez+1);
    fclose(fi);
    fclose(fout);
    return 0;
}