Cod sursa(job #21748)
| Utilizator | Data | 24 februarie 2007 11:08:27 | |
|---|---|---|---|
| Problema | Factorial | Scor | 5 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include<fstream.h>
#include<math.h>
unsigned long fo(unsigned long k) {
if(k/5==0) return 0;
else return k/5+fo(k/5);
}
long gg(unsigned long p) {
if(p==0) return 1;
if(p==5) return -1;
if(p%25==0) return -1;
unsigned long c,n=0,m=5*10;
while(n+5<=m) {
c=(m+n)/2-((m+n)/2)%5;
if(fo(c)<p) n=c+5;
if(fo(c)>p) m=c-5;
if(fo(c)==p) n=m+5;
}
return c;
}
main() {
unsigned long p;
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
g<<gg(p);
return 0;
}
