Cod sursa(job #2828430)
| Utilizator | Data | 7 ianuarie 2022 11:55:48 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.72 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int p;
int count0(int n)
{
int s=0,p=5;
while(p<=n)
{
s=s+n/p;
p=p*5;
}
return s;
}
int cautbin(int x)
{
int st=1,dr=1000000005;
bool ok=false;
int mij,a,ind=0;
while(st<=dr)
{
mij=(st+dr)/2;
a=count0(mij);
if(a>=x)
{
ind=mij;
dr=mij-1;
if(a==x)
ok=true;
}
else
st=mij+1;
}
if(ok)
return ind;
return -1;
}
int main()
{
fin>>p;
fout <<cautbin(p)<<"\n";
return 0;
}
