Cod sursa(job #2913486)
| Utilizator | Data | 14 iulie 2022 19:15:56 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.48 kb |
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define ll long long int
inline ll v(ll k)
{
int z=0;
for (int i=5; i<=k; i*=5) z+=floor(k/i);
return z;
}
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
ll P;
fin >> P;
map<ll, int> mp;
ll a=5*P;
while(v(a)!=P && mp[a]==0)
{
mp[a]=1;
if (v(a)>P) a-=5*(v(a)-P); else a+=5*(P-v(a));
}
if (v(a)!=P) a=-1;
fout << a;
}