2024年PAT乙级考试 B-1合成2024 题型:数学

208 阅读1分钟

image.png

这道题就是数学思路。

首先,前n个偶数的求和公式为:n(n+1)n*(n+1)、推导过程如下:

image.png

前m个奇数的求和公式为:mmm^{m}。推导过程如下:

image.png

正难则反,这里直接想什么情况不满足条件:

1.m是奇数不满足条件。

2.m是偶数满足条件。

3.相加和大于2024不满足条件。

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

int main()
{
	int t; cin >> t;
	while(t--)
	{
		int n, m; cin >> n >> m;
		if (m%2==0&&n * (n + 1) + (m * m) <= 2024)
		{
			cout << "yes" << endl;
		}
		else cout << "no" << endl;
	}
	return 0;
}

image.png

当然,即便是推不出来前n个偶数的求和公式和前m个奇数1的求和公式,可以直接套等差数列求和公式,让计算机帮你求:


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

int main()
{
	int t; cin >> t;
	while(t--)
	{
		int n, m; cin >> n >> m;
		if (m%2==0&&(2+n)*n/2+(1+(2*m-1))*m/2 <= 2024)
		{
			cout << "yes" << endl;
		}
		else cout << "no" << endl;
	}
	return 0;
}

image.png