Cod sursa(job #2444398)
Utilizator | Maracine Mihail Robert Rmrn56 | Data | 31 iulie 2019 14:46:49 |
---|---|---|---|
Problema | Factorial | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.75 kb |
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int m,N=1000000000;
int numarZero(int n){
int s=0;
if(n==0) return 1;
for(long long i=5;n/i>=1;i*=5)
s+=n/i;
return s;
}
int cautBinara(int p){
int s=0,d=N,z;
while(s<=d){
m=( s + d ) / 2;
z = numarZero(m);
if(p == z) {
int x=m;
while(numarZero(x) == z)
x--;
return x+1;}
if(p > z)
{
s = m + 1;
}
if(p < z)
{
d = m - 1;
}
}
}
int main ()
{
long long P,auxP=0,i=1,N;
fin >> P;
fout<<cautBinara(P);
}