Cod sursa(job #1901004)
Utilizator | Data | 3 martie 2017 18:18:48 | |
---|---|---|---|
Problema | Factorial | Scor | 35 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <fstream>
#include <cstdio>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int main()
{
long long N,P,x=1,y=100000000,i,p=5,s=0;
in>>P;
while(x<y)
{
i=(x+y)/2;
s = 0;
p = 5;
while(p<=i){
s=s+i/p;
p=p*5;
}
if(s<P)x=i+1;
else y=i;
}
s = 0;
p = 5;
while(p<=i){
s=s+i/p;
p=p*5;
}
if (s!=P)
out<<-1;
else out<<y;
return 0;
}