Pagini recente » Cod sursa (job #569325) | Cod sursa (job #1642777) | Cod sursa (job #3003310) | Cod sursa (job #2575934) | Cod sursa (job #2418492)
// 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;
while (!fin.eof())
{
fin >> p;
fout << BinarySearch(p) << "\n";
}
}
long long GetNumOfZeros(long long x)
{
long long div = 5, sum = 0;
while (div <= x)
{
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)
{
int left = 0, right = 100000000, 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