Cod sursa(job #1769398)
| Utilizator | Data | 2 octombrie 2016 14:59:28 | |
|---|---|---|---|
| Problema | Factorial | Scor | 5 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n;
int zeros(int x)
{
int p=5, k=0;
while (p<=x)
{
k+=x/p;
p*=5;
}
return k;
}
void binarySearch(int x)
{
bool ok;
int l=1, r=1<<30, mid;
while (l<=r && !ok)
{
mid=(l+r)/2;
int nr=zeros(mid);
if (x==nr) { fout<<mid-mid%5; ok=1; }
else if (x<nr) r=mid-1;
else l=mid+1;
}
if (!ok) fout<<-1;
}
int main()
{
fin>>n;
if (!n) fout<<1;
else binarySearch(n);
return 0;
}
