Pagini recente » Cod sursa (job #1130020) | Cod sursa (job #1938083) | Cod sursa (job #2067989) | Cod sursa (job #774736) | Cod sursa (job #3252484)
// https://www.infoarena.ro/problema/gfact
#include <bits/stdc++.h>
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int p, q, b, nr;
void getPrime()
{
int n = p;
vector<int> factor_list;
unordered_map<int, int> factor_pow;
factor_list.push_back(1), factor_pow[1]++;
while (n > 1)
{
int f = 2;
while (n % f != 0)
f++;
if (!factor_pow.count(f))
factor_list.push_back(f);
factor_pow[f]++;
n /= f;
}
int bigPrime = 0;
for (int i = 0; i < factor_list.size(); i++)
{
int power = pow(factor_list[i], factor_pow[factor_list[i]]);
if (power > bigPrime)
{
b = factor_list[i];
nr = factor_pow[factor_list[i]];
bigPrime = power;
}
}
}
long long fact_b(const long long n)
{
long long x = 0, i = b;
while (true)
{
x += n / i;
if (i * b > LONG_MAX)
break;
i *= b;
}
return x;
}
long long findSolution(const long long st, const long long dr)
{
const long long mid = (st + dr) / 2, val = fact_b(mid);
cout << st << ' ' << dr << ' ' << val << '\n';
if (val == nr * q * 1LL)
return mid;
if (val > nr * q * 1LL)
return findSolution(st, mid - 1);
return findSolution(mid + 1, dr);
}
int main()
{
fin >> p >> q;
getPrime();
cout << b << ' ' << nr << '\n';
long long sol = findSolution(1, LONG_LONG_MAX);
if (sol != 1)
sol -= sol % b;
fout << sol;
return 0;
}