syu问题 A: 一个数学问题

版权声明:转载请注明出处 https://blog.csdn.net/qq_41431457/article/details/88368724

题目描述

当0<a<b<n时,(a^2+b^2+m)/(ab)是一个整数。

输入

输入包含多组测试数据。每组输入为两个整数n和m(0<n<=100),当n=m=0时,输入结束。

输出

对于每组输入,输出样例标号和满足要求的整数对的个数。

样例输入

10 1
20 3
30 4
0 0

样例输出

Case 1: 2
Case 2: 4
Case 3: 5

暴力:

#include<bits/stdc++.h> 
using namespace std;
int n,m;
int main()
{
	int k=1;
	while(cin>>n>>m&&(n||m))
	{
		int ans=0;
		for(int i=2;i<n;i++)
		for(int j=1;j<i;j++)
		if(((i+j)*(i+j)+m)%(i*j)==0) ans++;
		cout<<"Case "<<k++<<':'<<' '<<ans<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41431457/article/details/88368724
今日推荐