Cod sursa(job #3282827)
| Utilizator | Data | 6 martie 2025 22:01:48 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.78 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int Count(int n){
int ret = 0;
while(n){
ret+=n/5;
n/=5;
}
return ret;
}
int cautare(int st,int dr){
int mij, ret=-1;
while(st<=dr){
mij = (st+dr)/2;
if(Count(mij) == p){
ret = mij;
dr = mij-1;
}
else if(Count(mij) < p){
st = mij+1;
}
else{
dr = mij-1;
}
}
return ret;
}
int main(){
fin >> p;
if(p==0){
fout << 1;
return 0;
}
int l = 1;
int r = 5*(p+1);
fout << cautare(l,r);
return 0;
}
