跳到正文

题解

P8302 [CoE R4 B/Stoi2041] 龙拳

nomonick约 4 分钟
原文
文章信息与版本

文章信息

发布
2022年4月28日
收录
2026年8月5日
更新
2026年11月18日
篇幅
约 4 分钟
获赞
11
题目
P8302

版本

  1. v1当前

题面:link

算法分析

设: h(x)h(x) 为 xx 的最小质因数

∴xg(x)=h(x) , x=h(x)×g(x)\therefore \frac{x}{g(x)} = h(x)\ ,\ x = h(x) \times g(x) ∴f(x)=(h(x)+1)×g(x)=xh(x)×(h(x)+1)\therefore f(x) = (h(x)+1) \times g(x) = \frac{x}{h(x)} \times (h(x) + 1)

当 h(x)=2h(x) = 2 时: h(x)+1=3 h(x) + 1 = 3

当 h(x)⩾3h(x) \geqslant 3 时: 2∤h(x)  ,  h(x)+1=2×k2 \nmid h(x) \; , \; h(x) + 1 = 2 \times k

∴∀  x⩾2×k+1 (k∈N∗)  ,  2∣f(x)\therefore \forall \; x \geqslant 2 \times k + 1\ (k \in N^*) \; , \; 2 \mid f(x)

当 h(x)=3h(x) = 3 时: h(x)+1=4=2×2h(x) + 1 = 4 = 2 \times 2

不妨设:x=2a×3b×kx = 2^a \times 3^b \times k

f(x)=2a−1×3b+1×k……f(a)(x)=20×3b+a×kf(a+1)(x)=22×3b+a−1×kf(a+2)(x)=21×3b+a×kf(a+3)(x)=20×3b+a+1×k\begin{aligned} f(x) & = 2^{a-1} \times 3^{b+1} \times k \\ & \dots \dots \\ f^{(a)}(x) &= 2^{0} \times 3^{b+a} \times k \\ f^{(a+1)}(x) & = 2^{2} \times 3^{b+a-1} \times k \\ f^{(a+2)}(x) & = 2^{1} \times 3^{b+a} \times k \\ f^{(a+3)}(x)& = 2^{0} \times 3^{b+a+1} \times k\end{aligned}

综上:

  1. 3∣k3 \mid k
  2. f(m0)(x)f^{(m_0)}(x) 为 xx 变为的第一个只含有少于两个因子为 22 或 含有因子 33 的数。

code

C++
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	int x = 0,f = 1ll;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-') f = -1ll;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = (x << 1ll) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return f * x;
}
inline void write(int x)
{
	if (x < 0) x = -x, putchar('-');
	if (x <= 9) putchar(x+'0');
	if (x > 9) write(x/10),putchar((x % 10) + '0');
}
int n,k,tot,ans,tmp;
int prime[SIZE],minn[SIZE];
bool is_prime[SIZE];
inline void Euler()
{
	for (int i = 2; i < (int)3e7; ++i)
	{
		if (!is_prime[i]) prime[++tot]=i,minn[i]=i;
		for (int j = 1; j <= tot && i * prime[j] < (int)3e7; ++j)
		{
			is_prime[i*prime[j]] = true;
			minn[i*prime[j]] = prime[j];
			if (i % prime[j] == 0) break;
		}
	}
}
inline int solve()
{
	n = read(); k = read(); ans = -2; tmp = 0;
	if (k % 3 != 0) return -1;
	if (n % 3 == 0 && n % 2) return 0;
	if (n % 2 && n % 3)
	{
		n = n / minn[n] * (minn[n] + 1);
		tmp++;
	}
	while (n % 2 == 0)
	{
		ans ++;
		n /= 2;
	}
	return max(0,ans) + tmp;
}
signed main()
{
	Euler();
	for (int T = read(); T; --T) write(solve()),puts("");
	return 0;
}
原文
存档评论4 条抓取于