Pagini recente » 12345678910 | Istoria paginii runda/leiten/clasament | Cod sursa (job #1451693) | Cod sursa (job #174439) | Cod sursa (job #1391572)
#include <iostream>
#include <fstream>
std::ifstream input("fact.in");
std::ofstream output("fact.out");
int count(int v)
{
int contor = 0;
int module = 0;
int pas = 5;
while( pas < v )
{
contor += v / pas;
pas *= 5;
}
return contor;
}
int main(int argc, char* argv[] )
{
unsigned int P;
input >> P;
unsigned int s = 1;
unsigned int dr = 1 << 31;
while ( s <= dr )
{
unsigned int mij = (s+dr)/2;
int val = count(mij);
if ( val == P )
{
while( count(mij) == P )
{
--mij;
}
output << ++mij;
return 0;
}
else
{
if ( val < P )
{
s = mij + 1;
}
else
{
dr = mij - 1;
}
}
}
output << "imposibil";
return 0;
}