Cod sursa(job #2444717)
| Utilizator | Data | 1 august 2019 10:56:24 | |
|---|---|---|---|
| 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 f("fact.in");
ofstream g("fact.out");
long long p;
int functie_magica(int n)
{
int s=0,p=5;
while(n>=p)
{
s+=n/p;
p*=5;
}
return s;
}
int cautare_binara(int st, int dr, int p)
{
int mij=(st+dr)/2,poz=-1;
while(st<=dr)
{
mij=(st+dr)/2;
if(functie_magica(mij)==p)
{
poz=mij;
dr=mij-1;
}
else if(functie_magica(mij)>p)dr=mij-1;
else st=mij+1;
}
return poz;
}
int main()
{
f>>p;
g<<cautare_binara(1,500000000,p);
return 0;
}
