Cod sursa(job #2822179)
| Utilizator | Data | 23 decembrie 2021 17:57:21 | |
|---|---|---|---|
| Problema | Factorial | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int n,P;
int zero(int x){
int Nrz=0,put=1;
while (put<=x){
put*=5;
Nrz+=(x/put);
}
return Nrz;
}
int caut(int st, int dr){
int a=-1,zr;
while (st<=dr){
int mij=(st+dr)/2;
zr=zero(mij);
if (zr==P){
a=mij;
dr=mij-1;
}
else if (zr>P) dr=mij-1;
else if (zr<P) st=mij+1;
}
return a;
}
int main()
{
in>>P;
out<<caut(1, 100000000);
return 0;
}
