Cod sursa(job #2793453)
| Utilizator | Data | 3 noiembrie 2021 17:37:36 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.66 kb |
#include<iostream>
#include<fstream>
#include<climits>
using namespace std;
int i, p, sol=-1;
int calc(int x)
{
long long j = 5;
int sum = 0;
while(j <= x)
{
sum += x / j;
j = j * 5;
}
return sum;
}
int main()
{
ifstream cin("fact.in");
ofstream cout("fact.out");
cin >> p;
int st = 1, dr = 500000000;
while(st <= dr)
{
int mij = (st + dr) / 2;
if(calc(mij) >= p)
{
dr = mij - 1;
if(calc(mij)==p)
sol = min(sol, mij);
}
else
{
st = mij + 1;
}
}
cout << sol;
}
