Pagini recente » Cod sursa (job #456831) | Cod sursa (job #2301968) | Cod sursa (job #1709567) | Cod sursa (job #1946066) | Cod sursa (job #1654725)
#include <iostream>
#include <fstream>
using namespace std;
int n;
int nrz(int n)
{
//cout<<n<<" ";
int nr=0;
for(int i=5;i<=n;i*=5)
nr+=n/i;
//cout<<n<<" ";
//cout<<nr<<endl;
return nr;
}
int cautare(int st, int dr)
{
if(st>dr)return -1;
int poz=(st+dr)/2;
//cout<<poz<<" ";
int ok=nrz(poz);
//cout<<poz<<endl;
if(ok==n)return poz;
else if(ok>n)cautare(st,poz-1);
else if(ok<n)cautare(poz+1,dr);
}
int main()
{
ifstream f("fact.in");
f>>n;
f.close();
ofstream g("fact.out");
if(n==0)g<<1;
else{
int ok=cautare(0,100000000);
if(ok>0) g<<ok-ok%5;
else g<<ok;
}
return 0;
}