Cod sursa(job #1251963)

Utilizator torckySuciu Victor torcky Data 30 octombrie 2014 09:01:50
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<cstdio>
using namespace std;
int pow5(int n)
{
    int s=0;
    long long p=5;
    while(p<=n)
    {
        s=s+n/p;
        p=p*5;
    }
    return s;
}
int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    int p,st=1,dr=1000000000,med,last=-1,s;
    scanf("%d",&p);
    ///search
    while(st<dr){
        med=(st+dr)/2;
        s=pow5(med);
        if (s>p){
            dr=med-1;
        }
        if (s<p){
            st=med+1;
        }
        if (s==p){
            last=med;
            dr=med-1;
        }
    }
    if (pow5(st)==p){
        last=st;
    }
    printf("%d\n",last);
    return 0;
}