Cod sursa(job #2660081)
| Utilizator | Data | 18 octombrie 2020 08:43:24 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.72 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f ("factorial.in");
ofstream g ("factorial.out");
int n;
int p;
void citire ()
{
f>>n;
}
int fact(long long x)
{
int p=5;
int cont=0;
while(p<=x)
{
cont+=x/p;
p*=5;
}
return cont;
}
void rezolvare()
{
long long st=1;
long long dr=1000000000;
long long mij=(st+dr)/2;
while(st<=dr)
{
if(fact(mij)==n && fact(mij-1)<n)
{
g<<mij;
return ;
}
if(fact(mij)<n)
st=mij+1;
else
dr=mij-1;
mij=(st+dr)/2;
}
}
int main()
{
citire();
rezolvare();
return 0;
}
