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) 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

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 ;
}

CF992B Nastya Studies Informatics 数学(因子) 暴力求解 第三道的更多相关文章

  1. Nastya Studies Informatics CodeForces - 992B (大整数)

    B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input ...

  2. Nastya Studies Informatics

    Nastya Studies Informatics   time limit per test 1 second   memory limit per test 256 megabytes   in ...

  3. CodeForces 992B Nastya Studies Informatics + Hankson的趣味题(gcd、lcm)

    http://codeforces.com/problemset/problem/992/B  题意: 给你区间[l,r]和x,y 问你区间中有多少个数对 (a,b) 使得 gcd(a,b)=x lc ...

  4. 【Codeforces 992B】Nastya Studies Informatics

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 因为gcd(a,b)=x 所以设a = nx b = mx 又有ab/gcd(a,b)=lcm(a,b)=y 则nmx = y 即n(m*x) ...

  5. Nastya Studies Informatics CodeForces - 992B(增长姿势)

    有增长姿势了 如果a * b == lcm * gcd 那么a和b为lcm因数  这个我之前真不知道emm... #include <bits/stdc++.h> #define mem( ...

  6. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  7. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  8. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  9. QuantLib 金融计算——数学工具之求解器

    目录 QuantLib 金融计算--数学工具之求解器 概述 调用方式 非 Newton 算法(不需要导数) Newton 算法(需要导数) 如果未做特别说明,文中的程序都是 Python3 代码. Q ...

随机推荐

  1. 非web下的PowerMockito单元测试

    一.介绍 PowerMockito 可以用来 Mock 掉 final 方法(变量).静态方法(变量).私有方法(变量).想要使用 PowerMockito Mock掉这些内容,需要在编写的测试类上使 ...

  2. Apache NiFi 核心概念和关键特性

    本文来源于官方文档翻译 NiFi 的核心概念 NiFi 最早是美国国家安全局内部使用的工具,用来投递海量的传感器数据.后来由 apache 基金会开源.天生就具备强大的基因.NiFi基本设计理念与 F ...

  3. 【Java例题】5.5 两个字符串中最长公共子串

    5. 查找两个字符串中含有的最长字符数的公共子串. package chapter5; import java.util.Scanner; public class demo5 { public st ...

  4. String——字符串

    首先看一下string的一部分源码吧 public final class String private final char value[]; 我们暂且只看这两行, 第一行String被final修 ...

  5. 使用PIP键盘输入数字小数位--Smart LCD

    应用范例: 使用TOPWAY Smart LCD (HMT050CC-C) 使用PIP键盘输入数字小数位 第一步 建立工程 第二步 建立三个页面,导入图片 点击工作区域, 右面显示页面属性 属性中Ba ...

  6. 洛谷 P3628 [APIO2010]特别行动队

    题意简述 将n个士兵分为若干组,每组连续,编号为i的士兵战斗力为xi 若i~j士兵为一组,该组初始战斗力为\( s = \sum\limits_{k = i}^{j}xk \),实际战斗力\(a * ...

  7. 直击根源:微信小程序中web-view再次刷新后页面需要退两次

    背景 在上一章(直击根源:vue项目微信小程序页面跳转web-view不刷新)解决了vue在小程序回退不刷新的问题之后,会引出了一个刷新的页面需要点击返回两次才能返回上一个页面 问题描述 在A页面从B ...

  8. Javascript中将数字转换为中文的方法

    //js实现将数字1234转化为汉字字符串(一千二百三十四)(或大写汉字壹仟贰佰叁拾肆): /*阿拉伯数字转中文数字 中文数字的特点: 每个计数数字都跟着一个权位,权位有:十.百.千.万.亿. 以“万 ...

  9. git码云的使用基础(为了以后更好的协同操作)

    git手册 安装教程 windows 不需要什么操作点点点就好 设置一个文件夹当成本地仓库 第一次上传 git init# 创建一个本地的仓库 git add. 当前文件夹下所有内容# 添加到暂存区 ...

  10. 驰骋工作流引擎ccflow-流转自定义功能使用说明

    流转自定义功能使用说明 关键字: 驰骋工作流程快速开发平台 工作流程管理系统 工作流引擎 asp.net工作流引擎 java工作流引擎. 节点跳转 节点流转自定义 应用背景: 有一些流程在运行过程中是 ...