CF992B Nastya Studies Informatics 数学(因子) 暴力求解 第三道
1 second
256 megabytes
standard input
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.
The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).
In the only line print the only integer — the answer for the problem.
1 2 1 2
2
1 12 1 12
4
50 100 3 30
0
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 数学(因子) 暴力求解 第三道的更多相关文章
- Nastya Studies Informatics CodeForces - 992B (大整数)
B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input ...
- Nastya Studies Informatics
Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes in ...
- 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 ...
- 【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) ...
- Nastya Studies Informatics CodeForces - 992B(增长姿势)
有增长姿势了 如果a * b == lcm * gcd 那么a和b为lcm因数 这个我之前真不知道emm... #include <bits/stdc++.h> #define mem( ...
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- QuantLib 金融计算——数学工具之求解器
目录 QuantLib 金融计算--数学工具之求解器 概述 调用方式 非 Newton 算法(不需要导数) Newton 算法(需要导数) 如果未做特别说明,文中的程序都是 Python3 代码. Q ...
随机推荐
- UE4 本地化不起作用 SetCurrentCulture
UE4 本地化 FInternationalization::Get ().SetCurrentCulture ( TEXT ( "en" ) ) FInternationaliz ...
- UE4 游戏模块初始化顺序
最近看教学,有个讲解UE4初始化顺序的,记录一下. 首先创建一个Actor,Character,GameInstance,GameMode,LevelScriptActor(关卡),PlayerCon ...
- Android使用com.google.android.cameraview.CameraView进行拍照
import android.Manifest;import android.annotation.SuppressLint;import android.content.Context;import ...
- 暴风雨中的 online :.net core 版博客站点遭遇的高并发问题进展
今天暴风雨袭击了杭州,而昨天暴风雨(高并发问题)席卷了园子,留下一片狼藉. 在前天傍晚,我们进行了 .net core 版博客站点的第二次发布尝试,在发布后通过 kestrel 直接监听取代 ngin ...
- 转载 | Sublime Text3 安装以及初次配置
本文引自:http://blog.csdn.net/u011272513/article/details/52088800 工具:官网下载:Sublime Text3 安装:直接运行安装.http:/ ...
- 转载 | float 清除浮动的7种方法
什么叫浮动:浮动会使当前标签脱离文档流,产生上浮的效果,同时还会影响周边元素(前后标签)及父级元素的位置和width,height属性.下面用一个小例子来看一看浮动的全过程:1.首先我们新建一个网页, ...
- [实践]redhat linux5.3安装tomcat
1.安装准备 操作系统:RedHat 5 (自带apache2.2.3) 安装tomcat前首先要安装jdk: 查看系统是否安装了jdk或tomcat的命令: rpm -qa | grep java ...
- 第三方登录之QQ
public class MainActivity extends AppCompatActivity { private Button btn; private TextView tv; priva ...
- 基于.NET Core开发的个人博客发布至CentOS小计
早些时候,使用 .NET Framework 开发网站,只能部署在 Windows 服务器上面,近两年 .NET Core 如火如荼,乘此机会赶紧上车,最近将自己利用 .NET Core 开发的个人博 ...
- 什么时候使用redis?什么时候使用memcache?
要清楚为什么,redis具有高可用特性,并且可固化,但特性有时候不能成为选择他的理由,一些业务场景中并不需要这样的特性. 什么时候倾向于选择redis? 1.复杂数据结构 value是哈希,列表, ...