Cod sursa(job #1213286)
| Utilizator | Data | 27 iulie 2014 19:02:38 | |
|---|---|---|---|
| Problema | Factorial | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include<fstream>
#define LL long long
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
LL A=0,B=2000000000,C,P;
LL f(LL n) {
LL S=0;
while(n>5) {
S+=n/5;
n=n/5;
}
return S;
}
int main() {
cin>>P;
while(B-A>1) {
C=(A+B)/2;
if(f(C)<P)
A=C+1;
if(f(C)>P)
B=C-1;
if(f(C)==P) { while(f(C)==P) C--;
C++;
cout<<C;
return 0; }
}
cout<<"-1";
return 0;
}
