Cod sursa(job #1712611)
Utilizator | Data | 3 iunie 2016 09:14:22 | |
---|---|---|---|
Problema | Factorial | Scor | 95 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
long long a=305175781,p,n=0,x=1220703125,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||p<a) {a--;a/=5;x/=5;k=4;}
else {p=-1;}
}
if (p==0) fout<<n;
else fout<<"-1";
return 0;
}