Pagini recente » Info Oltenia 2018 Proba Individuala | Clasament oji_2007_10 | Info Oltenia 2018 Proba Individuala | Cod sursa (job #2190505) | Cod sursa (job #2594402)
#include <iostream>
#include <fstream>
using namespace std;
long long nr_zerouri(long long numar)
{
long long solutie = 0;
for(long long i = 5; i <= numar; i*=5)
{
solutie += numar/i;
} //face suma de numar impartit la 5^1, ^2, ^k....
return solutie;
}
int main()
{
fstream fin("fact.in", ios::in);
fstream fout("fact.out", ios::out);
long long minim = 1, maxim = 400000015, mijloc, numar; //limitele lui n
bool gasit = false;
int p;
fin >> p;
if (p == 0)
{
fout << 1;
}
else
{
while(minim < maxim)
{
//cautare binara
mijloc = (minim + maxim)/2;
cout << "Minim: " << minim << endl;
cout << "Mijloc: " << mijloc << endl;
cout << "Max: " << maxim << endl;
numar = nr_zerouri(mijloc);
if(numar == p)
{
fout << mijloc - mijloc%5;
gasit = true;
break;
}
else if(numar < p)
{
minim = mijloc + 1;//cauta la dreapta
}
else
{
maxim = mijloc - 1;//cauta la stanga
}
}
if (gasit == false)
{
fout << -1;
}
}
}