Cod sursa(job #2000276)
Utilizator | Todoran Alexandru Raul alextodoran | Data | 13 iulie 2017 12:07:12 |
---|---|---|---|
Problema | Factorial | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long p,l,r,m;
long long vczalf(long long n)
{
long long k=0;
while(n>0){k+=n/5; n/=5;}
return k;
}
int main()
{
ifstream fin ("fact.in");
ofstream fout ("fact.out");
fin>>p;
l=1;
r=1ll<<60;
long long best=-1;
while(l<r)
{
m=(l+r)/2;
if(vczalf(m)>=p){best=m;r=m-1;}
else l=m+1;
}
if(vczalf(best)==p)fout<<best;
else fout<<"-1";
fout<<"\n";
return 0;
}