题解:P12869 [蓝桥杯 2025 国 Python A] 特殊整数对的数量
SuyctidohanQ · · 题解
思路分析
看到要求
如果直接枚举
for(LL i = 2025; i <= (LL)(1e6); i += 2025)
对于条件 __gcd() 函数计算最大公因数,判断一下是不是
if(a < b && __gcd(a, b) == 1)
对于条件
代码实现
这里提供一份 C++ 的暴力代码:
#include<bits/stdc++.h>
#define please return
#define AC 0
using namespace std;
typedef long long LL;
LL ans = 0;
signed main() {
for(LL i = 2025; i <= (LL)(2e6); i += 2025) {
for(LL j = max(1LL, i - (LL)(1e6)); j <= min(i * 1LL, (LL)(1e6)); j++) {
LL x = i - j;
if(j < x && __gcd(j, x) == 1) ++ans;
}
}
printf("%lld\n", ans);
please AC;
}
运行可得答案为
使用 Python 输出答案:
print(93816892)