Cod sursa(job #1822872)
Utilizator | Data | 5 decembrie 2016 18:25:51 | |
---|---|---|---|
Problema | Factorial | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
int calculare(int nr)
{
int countq=0;
int putere=5;
while(nr/putere>0)
{
countq=countq+nr/putere;
putere=putere*5;
}
return countq;
}
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
int st,dr,mij;
int p,u;
fin>>p;
st=1;
dr=p*5;
while(st<=dr)
{
mij=(st+dr)/2;
if(calculare(mij)<p) st=mij+1;
else
st=mij-1;
if(calculare(mij)==p)
int u=1;
}
if(u) fout<<st;
else
fout<<-1;
cout<<'\n';
return 0;
}