Cod sursa(job #1210130)
| Utilizator | Data | 19 iulie 2014 12:33:25 | |
|---|---|---|---|
| Problema | Factorial | Scor | 85 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int funt(int x)
{
int sol=0;
int po=5;
while(x/po>0)
{
sol+=x/po;
po*=5;
}
return sol;
}
void cautbin(int lo, int hi)
{
while(hi-lo>1)
{
int mid=lo+(hi-lo)/2;
if(funt(mid)<p) lo=mid;
else hi=mid;
}
if(hi==p*5) fout<<-1<<"\n";
else fout<<hi<<"\n";
}
int main()
{
fin>>p;
//caz particular
if(p==0) {fout<<1<<"\n";return 0;}
cautbin(-1,p*5);
}
