B. Nastya Studies Informatics
程序员文章站
2022-06-08 15:54:04
...
题解:
有几个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;
}
推荐阅读
-
B. Nastya Is Playing Computer Games---(水题模拟)Codeforces Round #546 (Div. 2)
-
codeforces B. Nastya and Door
-
Codeforces Round #489 (Div. 2) B. Nastya Studies Informatics(数学+枚举优化)
-
Codeforces Round #489 (Div. 2) ---- B. Nastya Studies Informatics
-
Codeforces 1341 B. Nastya and Door
-
B. Nastya Studies Informatics
-
Nastya Studies Informatics【好多细节、好坑的题,或许是我太弱了吧,不过我找到了WA的原因了】