Cod sursa(job #2067523)
Utilizator | Data | 16 noiembrie 2017 16:08:34 | |
---|---|---|---|
Problema | GFact | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.43 kb |
#include <fstream>
using namespace std;
ifstream cin("gfact.in");
ofstream cout("gfact.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=1LL<<59;
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;
}