首页 技术 正文
技术 2022年11月23日
0 收藏 642 点赞 5,153 浏览 1966 个字

Nastya Studies Informaticstime 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) 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.

Examplesinput

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,r,a,b,问在l到r的范围内有多少对数(两个数不能相同,顺序可以不同)满足gcd(x,y)=a,lcm(x,y)=b

枚举b的因子个数,再看这些因子每每两个的最大公约数是否等于a,等于a满足条件情况加一

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e3 + ;
typedef long long ll;
ll gcd( ll p, ll q ) {
if( p == ) {
return q;
}
if( q == ) {
return p;
}
return gcd( q, p%q );
}
int main(){
std::ios::sync_with_stdio(false);
ll l, r, a, b;
//cout << gcd( 16, 4 ) << endl;
while( cin >> l >> r >> a >> b ) {
ll num = ;
vector<ll> e;
for( ll i = ; i * i <= b; i ++ ) {
if( b % i == ) {
e.push_back(i);
if( i != b/i ) {
e.push_back(b/i);
}
//debug(i),debug(b/i);
}
}
for( ll i = ; i < e.size(); i ++ ) {
for( ll j = ; j < e.size(); j ++ ) {
if( gcd( e[i], e[j] ) == a && e[i] * e[j] == a * b
&& e[i] >= l && e[i] <= r && e[j] >= l && e[j] <= r ) {
num ++;
}
}
}
cout << num << endl;
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848