Cod sursa(job #1550268)

Utilizator PopoviciRobertPopovici Robert PopoviciRobert Data 13 decembrie 2015 14:38:47
Problema GFact Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <cstdio>
#define SQRT 50000
int exp[SQRT],fact[SQRT],n,b;
inline int cauta(long long nr){
    int i;
    long long p,con;
    i=0;
    while(i<n){
        p=fact[i];
        con=0;
        while(p<=nr){
            con+=(nr/p);
            p=p*fact[i];
        }
        if(con<exp[i]*b)
            return 0;
        i++;
    }
    return 1;
}
int main(){
    FILE*fi,*fout;
    long long rez,pas,d,a,e;
    fi=fopen("gfact.in" ,"r");
    fout=fopen("gfact.out" ,"w");
    fscanf(fi,"%lld%d" ,&a,&b);
    d=2;
    n=0;
    while(d*d<=a){
        e=0;
        while(a%d==0){
            a/=d;
            e++;
        }
        if(e>0){
         exp[n]=e;
         fact[n]=d;
         n++;
        }
        d++;
    }
    if(a>1){
          exp[n]=1;
          fact[n]=a;
          n++;
    }
    rez=0;
    for(pas=1LL<<50LL;pas;pas/=2)
        if(cauta(rez+pas)==0){
            rez+=pas;
        }
    fprintf(fout,"%lld" ,rez+1);
    fclose(fi);
    fclose(fout);
    return 0;
}