Cod sursa(job #2808894)
| Utilizator | Data | 25 noiembrie 2021 17:03:55 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int i, p, n=-1;
int calculare(int x)
{
long long j = 5;
int sum = 0;
while(j <= x)
{
sum += x/j;
j=j*5;
}
return sum;
}
int main()
{
fin >> p;
int st = 1, dr = 500000000;
while(st <= dr)
{
int mijloc = (st + dr) / 2;
if(calculare(mijloc) >= p)
{
dr = mijloc - 1;
if(calculare(mijloc)==p)
n = mijloc;
}
else
{
st = mijloc+1;
}
}
fout << n;
}
