codeforces 992B Nastya Studies Informatics

http://www.elijahqi.win/archives/3766
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)=x

GCD(a,b)=x
and LCM(a,b)=y

LCM(a,b)=y
, where GCD(a,b)

GCD(a,b)
denotes the greatest common divisor of a

a
and b

b
, and LCM(a,b)

LCM(a,b)
denotes the least common multiple of a

a
and b

b
.

You are given two integers x

x
and y

y
. You are to find the number of good pairs of integers (a,b)

(a,b)
such that l≤a,b≤r

l≤a,b≤r
. Note that pairs (a,b)

(a,b)
and (b,a)

(b,a)
are considered different if a≠b

a≠b
.

Input
The only line contains four integers l,r,x,y

l,r,x,y
(1≤l≤r≤109

1≤l≤r≤109
, 1≤x≤y≤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)

(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 l≤a,b≤r

l≤a,b≤r
.

枚举x的倍数 暴力

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int l,r,x,y,ans;
inline int gcd(int x,int y){
    return !y?x:gcd(y,x%y);
}
int main(){
//  freopen("b.in","r",stdin);
    scanf("%d%d%d%d",&l,&r,&x,&y);int ans=0;
    ll tmp=(ll)x*y;
    for (ll i=x,j=0;i<=r&&j<=1e5;i+=x,++j){
        if (i<l) continue;if (tmp%i) continue;
        ll t=tmp/i;if (i>t) continue;
        if (t>r) continue;if(gcd(t,i)!=x) continue;
        ++ans;if (t!=i) ++ans;
    }printf("%d\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值