B. Nastya Studies Informatics(数学)

B. Nastya Studies Informatics
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
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)(a,b) good, if GCD(a,b)=xGCD(a,b)=x and LCM(a,b)=yLCM(a,b)=y, where GCD(a,b)GCD(a,b) denotes the greatest common divisor of aa and bb, and LCM(a,b)LCM(a,b) denotes the least common multiple of aa and bb.

You are given two integers xx and yy. You are to find the number of good pairs of integers (a,b)(a,b) such that la,brl≤a,b≤r. Note that pairs (a,b)(a,b) and (b,a)(b,a) are considered different if aba≠b.

Input

The only line contains four integers l,r,x,yl,r,x,y (1lr1091≤l≤r≤1091xy1091≤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)(a,b)(1,2)(1,2) and (2,1)(2,1).

In the second example there are four suitable good pairs of integers (a,b)(a,b)(1,12)(1,12)(12,1)(12,1)(3,4)(3,4) and (4,3)(4,3).

In the third example there are good pairs of integers, for example, (3,30)(3,30), but none of them fits the condition la,brl≤a,b≤r.

题意:a,b为两个正整数,l<= a,b <=r。x=gcd(a,b),y=lcm(a,b)。gcd是a,b的最大公约数,lcm是a,b的最小公倍数。给出l,r,x,y,求有多少种可能的a,b。

思路:如果直接暴力,利用x*y=a*b 来做的话,肯定会T!现在,我们设 a=n*m,b=m*z.那么,x=m,y=n*m*z,a*b=n*m*m*z。如果我们来枚举a的所有可能的话,1e9,太大,所以我们考虑枚举n的所有可能!!我们先来确定n的范围,最小为1,n最大值为sqrt(n*z),确定了范围后,就可以开始写了。

   #include "iostream"
    using namespace std;
    int gcd(int a,int b)
    {
        if(b==0) return a;
        return gcd(b,a%b);
    }
    int main()
    {
        int l,r,x,y,i,num,ans=0;
        cin>>l>>r>>x>>y;
        num=y/x; if(y%x!=0){cout<<"0"<


你可能感兴趣的:(数学)