Cod sursa(job #3252347)

Utilizator andrei257Andrei Enache andrei257 Data 29 octombrie 2024 12:17:30
Problema GFact Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
// https://www.infoarena.ro/problema/gfact

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ifstream fin("gfact.in");
ofstream fout("gfact.out");

int p, q;

ll factP(const ll n)
{
	ll x = 0, i = p;
	while (true)
	{
		cout << i << ' ';
		x += n / i;
		if (i * p > 60000000000000)
			break;
		i *= p;
	}
	cout << '\n';
	return x;
}

ll searchInput(const ll st, const ll dr)
{
	if (p == 1)
		return 0;
	const ll mid = (st + dr) / 2, val = factP(mid);
	cout << st << ' ' << dr << ' ' << val << '\n';
	if (val == q * 1LL)
		return mid;
	if (val > q * 1LL)
		return searchInput(st, mid - 1);
	return searchInput(mid + 1, dr);
}

int main()
{
	ll sol;
	fin >> p >> q;
	sol = searchInput(1, 60000000000000);
	if (sol > 1)
		sol -= sol % p;
	fout << sol;
	return 0;
}