1 条题解

  • 0
    @ 2026-5-2 10:25:59

    思路

    由题目标题的提示不难想到平方差公式 x2y2=(x+y)×(xy)x^2 - y^2 = ( x + y ) \times ( x - y ),可知枚举的 x+yx + yxyx - y 都是 dd 的因数,所以我们可以枚举 dd 的因数从而达到 O(d)O(\sqrt{d})

    代码

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    ll l,r,d,ans;
    int main(){
    	ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
    	cin>>d>>l>>r;
    	for(int i=1;i*i<=d;i++){
    		if(d%i==0){
    			//x+y=i x-y=d/i;
    			if((i+d/i)%2==0){
    				ll x=(i+d/i)/2;
    				ll y=x-i;
    				if(y*y<x*x && l<=y*y && x*x<=r) ans++;
    			}
    		}
    	}
    	cout<<ans;
    	return 0;
    }
    
    • 1

    信息

    ID
    9565
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者