Cod sursa(job #1519435)

Utilizator emiiMihailescu Ionut Emanuel emii Data 7 noiembrie 2015 12:37:59
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int sol(int x){
    int n=5,ans=0;
    while(n<=x)
        ans+=x/n,n*=5;
    return ans;
}

int main()
{int p;
f>>p;
int l=1,r=1000000000;
while(l<=r){
    int mij=(l+r)/2,s=sol(mij);
    if(s<p)
        l=mij+1;
    else
            r=mij-1;
}
if(sol(l)==p)
    g<<l;
else
    g<<"-1";
return 0;
}