Cod sursa(job #2395868)
| Utilizator | Data | 2 aprilie 2019 22:28:49 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main(){
int p,mij,rez,st,dr,aux,p5=5,t=0,c=0;
fin>>p;
st=1;
dr=5*p;
while(st<=dr){
mij=(st+dr)/2;
aux=mij;
while(aux){
aux/=5;
t+=aux;
}
if(t<p){
st=mij+1;
}
else{
if(t==p){
rez=mij;
c++;
}
dr=mij-1;
}
t=0;
}
if(p==0) fout<<"1";
else if(c==0) fout<<"-1";
else if(c>0) fout<<rez;
return 0;
}
