专栏文章

题解:P1072 [NOIP2009 提高组] Hankson 的趣味题

P1072题解参与者 1已保存评论 1

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
1 条
当前快照
1 份
快照标识符
@miqgxhmy
此快照首次捕获于
2025/12/04 04:37
3 个月前
此快照最后确认于
2025/12/04 04:37
3 个月前
查看原文

题意

求满足 gcd(x,a0)=a1,lcm(x,b0)=b1gcd (x,a_0)=a_1, lcm (x,b_0)=b_1xx 个数。

思路

2×1092\times10^9 的暴力一看就是过不了的。这个时候我们容易想到求因数那道题,只需枚举 11b1\sqrt{b_1},对于每一个 iib1i\frac{b_1}{i},我们判断它们是否互不重复,并且是否符合题意,此时答案数加一。

Code

CPP
#include <bits/stdc++.h>
#define int long long
#define fro for
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen (".in","r",stdin);
	//freopen (".out","w",stdout);
	int n;
	cin>>n;
	while (n--)
	{
		int a,aa,b,bb;
		cin>>a>>aa>>b>>bb;
		int sum=0;
		for (int i=1;i*i<=bb;i++)
		{
			if (bb%i==0)
			{
				int other=bb/i;
				if (b*i/__gcd(b,i)==bb&&__gcd(i,a)==aa)
				sum++;
				if (other!=i/*另一个因数与i不同*/&&b*other/__gcd(b,other)==bb&&__gcd(a,other)==aa)
				sum++;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}

评论

1 条评论,欢迎与作者交流。

正在加载评论...