Cod sursa(job #1725268)
| Utilizator | Data | 5 iulie 2016 12:40:23 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.47 kb |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll P,N,E[100];
ll check(ll a){
ll rs = 0;
for(int i = 1;E[i] <= a;i++) rs+=a/E[i];
return rs;
}
int main(){
ifstream cin("fact.in");
ofstream cout("fact.out");
E[0] = 1;
for(int p = 1;p<=26;p++) E[p]=E[p-1]*5;
cin >> P;
if(P==0) return cout << 1,0;
ll step,rs;
for(step = rs = (1LL<<60);step;step>>=1)
if(check(rs-step) >= P) rs-=step;
if(check(rs) != P) cout << -1;else
cout << rs;
return 0;
}
