题解:P12345 [蓝桥杯 2025 省 A 第二场] 双子星的讯息

· · 题解

题意:

有多少个 n 满足 n+20255202 与 n+10244201 均为完全平方数。

思路:

由 ( a^2 - b^2 = 20255202 - 10244201 = 10011001 ), 设 d 为 10011001 的因数,则需满足:

d+\frac{10011001}{d}\geq9002\quad$ and ${\frac{10011001}{d}-d}\geq6402

结合以上可得d \leq 1299。

之后使用代码枚举 10011001≤1299 的因数数量即可。

Code:

#include<bits/stdc++.h>
using namespace std;
int ans;
int main()
{
    const int N=10011001;
    for(int d=1;d<=1299;d++)
    {
        if(N%d==0) ans++;
    }
    cout << ans;
    return 0;
}