Mai intai trebuie sa te autentifici.
Cod sursa(job #1213295)
| Utilizator | Data | 27 iulie 2014 19:14:03 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 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,R;
LL f(LL n) {
LL S=0;
while(n>0) {
S+=n/5;
n=n/5;
}
return S;
}
int main() {
cin>>P;
if(P==0) {cout<<1;
return 0;}
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) { if(f(C-1)==P) {
while(f(C)==P) C--;
C++;
}
cout<<C;
return 0; }
}
cout<<"-1";
return 0;
}
