跳到正文

题解

P11747 「TPOI-1A」鞋子特大号

liaoxingrui约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
获赞
1
题目
P11747

版本

  1. v1当前

Content

给定一个数 xx,你可以对其进行以下操作若干次,直到无法再操作:

  • 选择一个数 yy 满足 1≤y<x1 \le y < x 且 gcd⁡(x,y)≠1\gcd ( x , y ) \not = 1,并将 xx 变为 gcd⁡(x,y)\gcd ( x , y )。

现在有以下两种询问共 TT 个:

  • 1 x:给定 xx,求 xx 最多能进行几次操作;

  • 2 q:给定 qq,求出一个最小的 xx,使得 xx 最多能进行恰好 qq 次操作。

Solution

这两种询问都是要求出最多能进行多少次操作,而每次操作的 yy 都不能为 xx,所以 gcd⁡(x,y)\gcd ( x , y ) 最大为 xx 除去最小质因数,那么执行次数就为 xx 质因子个数减一。

还需要注意:

第二个操作要用 unsigned long long。

Code

C++
#include<bits/stdc++.h>
using namespace std;
int t,x,opt;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		cin>>opt>>x;
		if(opt==1){
			int cnt=0;
			for(int i=2;i<=sqrt(x);i++)
				while(x%i==0){
					cnt++;
					x/=i;
				}
			if(x!=1)
				cnt++;
			cout<<max(0,cnt-1)<<endl;
		}
		else
			cout<<((unsigned long long)1<<x+1)<<endl;
	}
	return 0;
}
原文