B. Nastya Studies Informatics

这里写图片描述

题解:

有几个trick点
当我们暴力枚举x的因子时,最多枚举到1e5即可。
枚举一半即可 当另一个因子小于i时 退回循环即可。
注意(a,b)当a=b时相等。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
    LL l,r,x,y;
    cin>>l>>r>>x>>y;
    LL sum = x*y;
    LL ans=0;
    for(LL i=x,j=0;i<=r&&j<=1e5;j++,i+=x)
    {
         if(i<l) continue;
         if(sum%i) continue;
         LL tmp = sum/i;if(i>tmp) break;
         if(tmp>r) continue;
         if(__gcd(tmp,i)!=x) continue;
         ++ans;
         if(tmp!=i) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/q451792269/article/details/80742254
今日推荐