Cod sursa(job #658561)
| Utilizator | Data | 9 ianuarie 2012 00:03:45 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.38 kb |
#include <fstream>
using namespace std;
int main(){
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p,nr,i,f,m,p5[1000];
fin>>p;
if(p==0){
fout<<1;
fout.close();
return 0;
}
p5[1]=5;
f=1;
while(p5[f]<=p*5){
p5[f+1]=p5[f]*5;
f++;
}
for(nr=0,i=5;nr<p;i+=5){
f=1;
while(i%p5[f]==0)
f++;
nr+=f-1;
}
if(nr==p) fout<<i;
else fout<<-1;
fout.close();
}
