Cod sursa(job #2724914)
| Utilizator | Data | 18 martie 2021 04:34:03 | |
|---|---|---|---|
| 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 f(int x){
int t=x;
while(x){
x /= 5;
t+=x;
}
return t;
}
int main() {
int x;
fin>>x;
if(x == 0){
fout << 1;
return 0;
}
int lt=1;
int mid, y;
int right = x;
while(lt<=right){
mid = lt+(right-lt)/2;
y=f(mid);
if(y==x) {
lt = mid;
break;
}
if(y<x){
lt = mid + 1;
} else {
right = mid - 1;
}
}
if(f(lt) == x){
fout << lt*5;
} else {
fout << -1;
}
return 0;
}
