【Codeforces 992B】Nastya Studies Informatics
Codeforces
2023-09-14 09:03:44 时间
【链接】 我是链接,点我呀:)
【题意】
【题解】
因为gcd(a,b)=x 所以设a = n*x b = m*x 又有a*b/gcd(a,b)=lcm(a,b)=y 则n*m*x = y 即n*(m*x)=y 所以枚举y的因子n 算出对应的y/n是否为x的倍数 如果是的话,则算出n,m的具体值 然后对于ab不加(避免重复计数)【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll l,r,x,y;
/*
a = n*x
b = m*x
a*b/x = y
n*m*x = y
n*(m*x) = y
*/
bool in_range(ll x){
if (x>=l && x<=r) return true;
return false;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> l >> r >> x >> y;
ll len = sqrt(y);
ll ans = 0;
for (ll n = 1;n <= len;n++)
if (y%n==0){
ll temp = y/n;
if (temp%x==0){
ll m = temp/x;
ll a = n*x;
ll b = m*x;
if (a>b) continue;
if (__gcd(a,b)==x && in_range(a) && in_range(b)){
if (a==b) ans++;else ans+=2;
}
}
}
cout<<ans<<endl;
return 0;
}
相关文章
- 【Codeforces Round #648 (Div. 2) D】Solve The Maze
- 【Codeforces 979B】Treasure Hunt
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B】Weakened Common Divisor
- 【27.85%】【codeforces 743D】Chloe and pleasant prizes
- 【codeforces 765B】Code obfuscation
- 【codeforces 797C】Minimal string
- 【codeforces Manthan, Codefest 17 C】Helga Hufflepuff's Cup
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
- Codeforces Round #452 (Div. 2)