Cod sursa(job #898222)

Utilizator MefistossMefistoss Mefistoss Data 28 februarie 2013 09:13:44
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<cstdio>
using namespace std;
int putere(int a)
{
    int c=0;
    for(int i=5;i<=a;i*=5) c+=a/i;
    return c;
}
int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    int p,mij,n;
    int st=1, dr;
    scanf("%d",&p);dr=p*5;
    if(p==0) {printf("1"); return 0;}
    while(st<dr)
    {
        mij=(st+dr)/2;
        n=putere(mij);
        if(p<=n) dr=mij;
        else st=mij+1;
    }
    if(putere(st)==p) printf("%d",st);
    else printf("-1");
    return 0;
}