Cod sursa(job #2799334)
| Utilizator | Data | 12 noiembrie 2021 21:54:02 | |
|---|---|---|---|
| Problema | Factorial | Scor | 15 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream cin ("fact.in");
ofstream cout ("fact.out");
int p, n=0, cnt=0, p5=0, ca, ok=2;
cin>>p;
ca=p*5; n=p;
while (ca>0)
{
p5+=ca/5;
ca/=5;
}
while (1)
{
if (p5==p){ok=0; break;}
else if (p5<p){ok=-1; break;}
else
{
cnt=1; ca=p;
while (ca%5==0){cnt++; ca/=5;}
p5-=cnt; n--;
}
}
if (p==0) cout<<1;
else
{
if (ok==0) cout<<n*5;
else cout<<-1;
}
}
