Pagini recente » Cod sursa (job #377273) | Cod sursa (job #497697) | preONI 2008 - Clasament Runda 3, Clasa a 10-a | Cod sursa (job #1414316) | Cod sursa (job #2418496)
// c++ test.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <fstream>
using namespace std;
long long GetNumOfZeros(long long x);
long long BinarySearch(long long p);
long long CorrectAnswer(long long x);
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
//cout << "Hello World!\n";
long long p;
fin >> p;
if (p != 0)
fout << BinarySearch(p);
else
fout << 1;
}
long long GetNumOfZeros(long long x)
{
long long div = 5, sum = 0;
while (x != 0)
{
x = x / div;
sum += x;
}
return sum;
}
long long CorrectAnswer(long long x)
{
long long val = GetNumOfZeros(x);
while (GetNumOfZeros(x - 1) == val && x > 0)
x--;
return x;
}
long long BinarySearch(long long p)
{
long long left = 0, right = 10000000000, mid;
while (left < right)
{
mid = (left + right) / 2;
long long num = GetNumOfZeros(mid);
if (num >= p)
right = mid;
else if (num < p)
left = mid + 1;
}
if (GetNumOfZeros(left) == p)
return left;
return -1;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file