Cod sursa(job #140842)

Utilizator toni2007Pripoae Teodor Anton toni2007 Data 22 februarie 2008 12:46:45
Problema GFact Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include<stdio.h>
#include<limits.h>
#define N INT_MAX
int main(){
    int p,q,k,s,i;
    freopen("gfact.in","r",stdin);
    freopen("gfact.out","w",stdout);
    scanf("%d%d",&p,&q);
    for (i=1;i<=N;++i){
        k=p;s=0;
        while(i/k>0){
             s+=i/k;
             k*=p;
        }
        if (s%q==0 && s>0){
           printf("%d",i);
           return 0;
        }
    }
    return 0;
}