Pagini recente » Cod sursa (job #1139023) | Cod sursa (job #2524789) | Cod sursa (job #2731416) | Cod sursa (job #1056862) | Cod sursa (job #2809151)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("adunare.in");
ofstream fout("adunare.out");
long getZeroes(long a)
{
long five = 5, zeroes = 0;
while (five <= a * 5)
zeroes += a / five, five *= 5;
return zeroes;
}
long binSrc(const long& a)
{
if (a == 0)
return 1;
long left = 1, right = a * 5;
while (left <= right)
{
long middle = left + (right - left) / 2, zeroes = getZeroes(middle);
if (zeroes == a)
return middle;
else if (zeroes < a)
left = middle + 1;
else if (zeroes > a)
right = middle - 1;
}
return -1;
}
void solve()
{
long a;
fin >> a;
long finding = binSrc(a);
if (finding == 1 || finding == -1)
fout << finding << '\n';
else
fout << finding - finding % 5 << '\n';
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1; fin >> t;
while (t--)
{
solve();
}
return 0;
}
/*
ifstream fin("input.in");
ofstream fout("output.out");
*/