Cod sursa(job #3168055)
| Utilizator | Data | 11 noiembrie 2023 14:44:47 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("grupuri.in");
ofstream cout("grupuri.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";
}
}
