Cod sursa(job #2624500)
Utilizator | Data | 4 iunie 2020 22:06:20 | |
---|---|---|---|
Problema | Factorial | Scor | 25 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long Fact(long P)
{
if(P==0)
return 1;
long result=5;
while(P)
{
long aux=result;
int nr=0;
while(aux%5==0)
{nr++;aux/=5;}
P-=nr;
result+=5;
}
if (P < 0)
return -1;
return result-5;
}
int main()
{
long P;
in>>P;
out<<Fact(P);
return 0;
}