Cod sursa(job #2067507)
Utilizator | Data | 16 noiembrie 2017 15:48:57 | |
---|---|---|---|
Problema | Factorial | Scor | 55 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.42 kb |
#include <fstream>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
#define ll long long
ll f(ll n)
{
ll sol=0;
while(n>0)
{
sol+=n/5;
n/=5;
}
return sol;
}
int main()
{
ll n,r=0,pas=1e15;
cin>>n;
while(pas)
{
if(f(r+pas)<n)
r+=pas;
pas/=2;
}
if(f(r+1)==n)
cout<<r+1;
else
cout<<-1;
return 0;
}