Cod sursa(job #3168056)
| Utilizator | Data | 11 noiembrie 2023 14:45:11 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
long long n,m,i,j,k,st,dr,mid,sum,aux,s,p;
int main () {
cin>>n;
st=1;
dr=9223372036854775807;
aux=1;
while (st<=dr) {
mid=(st+dr)/2;
p=5;
aux=0;
while (p<=mid) {
aux+=mid/p;
p*=5;
}
if (aux>=n) {
dr=mid-1;
}
else {
st=mid+1;
}
}
p=5;
aux=0;
while (p<=st) {
aux+=st/p;
p*=5;
}
if (aux==n) {
cout<<st;
}
else {
cout<<"-1";
}
}
