跳到正文

题解

暴力出奇迹

蒟蒻whker约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月24日
篇幅
约 2 分钟
题目
P12869

版本

  1. v1当前

提交答案题。于是暴搜。写一个双层循环,求出有多少对满足 1≤a<b≤1061\le a<b\le10^6 且 gcd⁡(a,b)=1\gcd\left(a,b\right)=1 且 (a+b) mod 2025=0\left(a+b\right)\bmod2025=0 的 (a,b)\left(a,b\right) 即可。注意 a<ba<b。

暴搜代码(C++)

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

int main() {
	int ans=0;
	for(int a=1;a<=1000000;++a) {
		for(int b=a+1;b<=1000000;b++) {
			if(__gcd(a,b)==1&&(a+b)%2025==0)
				++ans;
		}
	}
	cout <<ans<<endl;
	return 0;
}

暴力代码(Python)

Python
import math
ans=0
for a in range(1, 1000001):
    for b in range(a, 1000001):
        if math.gcd(a,b)==1 and (a+b)%2025==0:
            ans+=1
print(ans)

随后运行代码,小睡一会儿。

睡醒后得到答案为 9381689293816892,输出即可。

C++ code

C++
#include <bits/stdc++.h>
int main() {
	std::cout<<93816892<<std::endl;
	return 0;
}

Python code

Python
print(93816892)
原文