Cod sursa(job #3132384)
Utilizator | Data | 22 mai 2023 16:36:11 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.89 kb |
#include <bits/stdc++.h>
using namespace std;
int fact(int n, int k)
{
int s = 0;
while(n > 1)
{
s = s + n / k;
n = n / k;
}
return s;
}
int p, st, dr, mid, ok;
ifstream f("fact.in");
ofstream g("fact.out");
int main()
{
ios_base::sync_with_stdio(0);
f.tie(0);
g.tie(0);
f >> p;
st = 0, dr = 5e8, mid;
if(p == 0)
{
g << 1;
return 0;
}
while(st <= dr)
{
mid = (st + dr) / 2;
if(fact(mid, 5) == p)
{
g << (mid / 5) * 5;
ok = 1;
return 0;
}
else
{
if(fact(mid, 5) < p)
{
st = mid + 1;
}
else
{
dr = mid - 1;
}
}
}
if(!ok)
{
g << -1;
}
return 0;
}