Codeforces Round #489 (Div. 2)/B
output
standard output
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.
We define a pair of integers (a, b) good, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common divisorof a and b, and LCM(a, b) denotes the least common multiple of a and b.
You are given two integers x and y. You are to find the number of good pairs of integers (a, b) such that l ≤ a, b ≤ r. Note that pairs (a, b)and (b, a) are considered different if a ≠ b.
Input
The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).
Output
In the only line print the only integer — the answer for the problem.
Examples
input
Copy
1 2 1 2
output
Copy
2
input
Copy
1 12 1 12
output
Copy
4
input
Copy
50 100 3 30
output
Copy
0
Note
In the first example there are two suitable good pairs of integers (a, b): (1, 2) and (2, 1).
In the second example there are four suitable good pairs of integers (a, b): (1, 12), (12, 1), (3, 4) and (4, 3).
In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition l ≤ a, b ≤ r.
题意:求 l<=a,b<=r 范围内 gcd(a,b)=x,lcm(a,b)=y 的组数
题解:有题可得gcd(a/x , b/x) = 1, lcm(a/x , b/x) = y/x , 所以就求 [1 , y/x] 中相乘等于 y/x 且互质的 ( a/x , b/x) 组数,注意l<=a,b<=r 就行。
//#include<bits/stdc++.h>
//#include <unordered_map>
//#include<unordered_set>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#include<climits>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
using namespace std;
#define ll long long
#define MT(a,b) memset(a,b,sizeof(a))
const int INF = 0x3f3f3f3f;
const int ONF = -0x3f3f3f3f;
const int mod = 1e3;
const int maxn = 1e6+5;
const int N = 1e9+5;
const double PI = 3.141592653589;
const double E = 2.718281828459;
int l ,r, x, y;
int gcd(int a, int b){
return a%b==0?b:gcd(b,a%b);
}
bool check(ll a, ll b){
return a>=l&&a<=r&&b>=l&&b<=r;
}
int main()
{
scanf("%d%d%d%d",&l,&r,&x,&y);
int p = y/x;
int ans = 0;
if(y%x!=0) goto loop ; // 无解情况
for(int i = 1;i*i<=p;i++)
{
if(p%i==0&&gcd(p/i,i)==1&&check(p/i*x,i*x)) ans += 2; //因为a,b可以交换,所以加2。
}
if(p==1&&ans) ans --; //如果p=1, ans--,道理很简单,仔细想想就行
loop:printf("%d",ans);
return 0;
}