Cod sursa(job #805373)

Utilizator bondoralexandru bondor bondor Data 31 octombrie 2012 12:23:46
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<stdio.h>
int zero(int a){
    int n=0;
    while(a>=5){
        n+=a/5;
        a/=5;
    }
    return n;
}
int caut(int a){
    int i,pas,r=0;
    i=0;
    pas=1<<30;
    while(pas!=0){
        if(zero(i+pas)<a)
            i+=pas;
        pas/=2;
    }
    return i+1;
}
int main(){
    long p,s,i,n;
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%ld",&p);
    n=caut(p);
    if(zero(n)==p)
        printf("%d",n);
    else printf("-1");
    return 0;
}