Cod sursa(job #2609149)
| Utilizator | Data | 2 mai 2020 11:34:56 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | igorj_mentorat1 | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("fact.in");
ofstream g ("fact.out");
int n, c ;
long long st, dr, m, x ;
int main()
{
cin>>n;
st=1 ;
dr=10000000;
while(st<=dr)
{
m=(st+dr)/2 ;
x=m;
c=0;
while(m!=0)
{
c=c+m/5 ;
m=m/5;
}
if(c==n)
{
if(x-x%5==0) cout<<"1";
else cout<<x-x%5 ;
dr=-1 ;
}
else if(c>n) dr=(st+dr)/2-1 ;
else st=(st+dr)/2+1 ;
}
if(dr!=-1) cout<< "-1";
return 0;
}
