Cod sursa(job #2757787)
| Utilizator | Data | 6 iunie 2021 15:19:43 | |
|---|---|---|---|
| Problema | Factorial | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
const int val=500000000;
long long fact(long long n)
{
long long s=0,p=1;
while(n>=p)
{
p*=5;
s+=n/p;
}
return s;
}
int main()
{
int p;
in>>p;
long long st=0,dr=val,mij;
long long gasit=-1;
while(st<=dr)
{
mij=(st+dr)/2;
if(fact(mij)<p)
st=mij+1;
else if(fact(mij)>=p)
dr=mij-1,gasit=mij;
}
if(p>0)
out<<gasit;
else
out<<1;
return 0;
}
