Cod sursa(job #3319159)
| Utilizator | Data | 30 octombrie 2025 20:19:19 | |
|---|---|---|---|
| Problema | Factorial | Scor | 45 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.45 kb |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
int p, ans = -1;
fin>>p;
int a, b, k;
a = 0;
b = 1e8;
int last0;
while(a <= b) {
last0 = 0;
k = (a+b)/2;
while(k > 5) {
last0 += k/5;
k /= 5;
}
k = (a+b)/2;
if(last0 == p) {
ans = k;
}
if(last0 < p) {
a = k + 1;
} else {
b = k - 1;
}
}
fout<<ans;
return 0;
}