Cod sursa(job #1653607)
| Utilizator | Data | 16 martie 2016 12:12:19 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,k;
long long n=25,n1;
fin>>p;
if (p==0) fout<<'1';
else if (p<=5) fout<<p*5;
else
{
p-=6;if (p==0) fout<<"25";
while (p>=4)
{
p-=4;n+=25;n1=n;
for (k=0;n1%5==0;k++,n1/=5) {}
if (k>=p) {fout<<n;p=0;}
else p-=k;
}
if (p!=0) fout<<n+p*5;
}
return 0;
}
