1. 程式人生 > >Codeforces Round #489 (Div. 2) B. Nastya Studies Informatics (數論)

Codeforces Round #489 (Div. 2) B. Nastya Studies Informatics (數論)

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 divisor of 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

1 2 1 2

Output

2

Input

1 12 1 12

Output

4

Input

50 100 3 30

Output

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.

PS:題意:給出一個範圍 l,r,兩個數x,y。要求在【l,r】,找出一對a,b。使得gcd(a,b)=x,lcm(a,b)=y。問能找到多少對這樣的數。

題解:如果用a*b=x*y,肯定會超時。我們設a=n*x,b=x*m;就有,y=n*m*x,a*b=n*m*m*x;這樣得出,y必定整除x。已經gcd(a,b)=x,得出,gcd(a/x,b/x)=1->gcd(n,m)=1,又y=n*m*x,推出n*m=y/x.;然後直接列舉n,m就行了,細節看程式碼。

#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<stack>
#include<string>
const int maxn=5e5+10;
const int mod=1e9+7;
const int inf=1e8;
#define me(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&(-x)
typedef long long ll;
using namespace std;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int l,r,x,y;
    cin>>l>>r>>x>>y;
    if(y%x!=0)
        cout<<"0"<<endl;
    else
    {
        int num=y/x,ans=0;
        for(int i=1;i*i<=num;i++)//列舉到根號num就行了,每次+2,特判n==m的情況。
        {
            int j=num/i;
            if(num%i==0&&gcd(i,j)==1&&l<=i*x&&i*x<=r&&l<=j*x&&j*x<=r)
                    i==j?ans++:ans+=2;
        }
        cout<<ans<<endl;
    }
    return 0;
}