Cod sursa(job #2756441)
| Utilizator | Data | 31 mai 2021 18:56:51 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
typedef long long ll;
ll p,n;
ll nr(ll x)
{
ll pw=1;
ll rez=0;
for(ll i=1;i<=19;i++)
{
pw=pw*5LL;
ll q=x/pw;
rez+=q;
}
return rez;
}
int main()
{
fin>>p;
n=1e18;
ll st=1;
ll dr=1e14;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(nr(mij)>=p)
{
n=min(n,mij);
dr=mij-1;
}
else
st=mij+1;
}
if(nr(n)!=p)
fout<<-1;
else
fout<<n;
return 0;
}
