Cod sursa(job #1901867)
| Utilizator | Data | 4 martie 2017 11:39:49 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int zero(ull x){
ull p=5,rez=0;
while(p<=x){
rez+=(x/p);
p*=5;
}
if(!x) return 1;
return rez;
}
int main()
{
int p;
fin>>p;
if(!p || p==1){
fout<<1;
return 0;
}
ll st=0,dr=INT_MAX;
while(dr>st){
ll mij=(dr+st)/2;
if(zero(mij)<p) st=mij+1;
else dr=mij;
}
if(zero(st)!=p) fout<<-1;
else fout<<st;
return 0;
}
