Cod sursa(job #1712606)
Utilizator | Data | 3 iunie 2016 08:59:16 | |
---|---|---|---|
Problema | Factorial | Scor | 25 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
long long a=61035156,p,n=0,x=244140625,k=4;
fin>>p;
if (p==0) fout<<'1';
while (p>0)
{
if (p>=a&&k>0) {p-=a;n+=x;k--;}
else if (k>0) {a--;a/=5;x/=5;k=4;}
else {p=-1;}
}
if (p==0) fout<<n;
else fout<<"-1";
return 0;
}