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 ...
随机推荐
- Django REST framework的使用简单介绍
官方文档:https://www.django-rest-framework.org/ GitHub源码:https://github.com/encode/django-rest-framework ...
- 荔枝FM前端面试题
最近接到了荔枝FM的面试通知,遗憾的是没有拿到offer,但是这次面试呢,还是收获很大的,下面就来给大家说说我遇到的面试题 一面 一面是直接发了一套面试题到邮箱,开启了防作弊的,限时20分钟做完,下面 ...
- HTML 第5章CSS3美化网页元素
<span>标签: <span>标签是用来组合HTML文档中的行内元素,它没有固定的格式表示. 字体样式: 属性名 ...
- git的使用学习笔记
一.git Git 是一个开源的分布式版本控制系统,项目版本管理工具,可以在本地提交修改再合并到主分支上,最为出色的是它的合并跟踪(merge tracing)能力. 可以通过Linux命令进行增加, ...
- 论文阅读 | Falcon: Balancing Interactive Latency and Resolution Sensitivity for Scalable Linked Visualizations
作者: Dominik Moritz, Bill Howe, Jeffrey Heer 发表于CHI 2019, 三位作者都来自于University of Washington Interactiv ...
- c++随笔之编译器编译原理
/* C++编译器原理:1)首先明白声明与定义是两个不同的概念 extern int i;是声明,int i;是定义 函数就更简单了2)编译分为: 预编译:将宏替换,include等代码拷贝过来 编译 ...
- RocketMQ中PullConsumer的消息拉取源码分析
在PullConsumer中,有关消息的拉取RocketMQ提供了很多API,但总的来说分为两种,同步消息拉取和异步消息拉取 同步消息拉取以同步方式拉取消息都是通过DefaultMQPullConsu ...
- 分布式ID系列(5)——Twitter的雪法算法Snowflake适合做分布式ID吗
介绍Snowflake算法 SnowFlake算法是国际大公司Twitter的采用的一种生成分布式自增id的策略,这个算法产生的分布式id是足够我们我们中小公司在日常里面的使用了.我也是比较推荐这一种 ...
- CodeForces 526D Om Nom and Necklace
洛谷题目页面传送门 & CodeForces题目页面传送门 给定字符串\(a\),求它的每一个前缀,是否能被表示成\(m+1\)个字符串\(A\)和\(m\)个字符串\(B\)交错相连的形式, ...
- .net软件开发脚本规范-SVN标准
一. SVN标准 1) 提交代码前先获取最新代码 2) 提交时需要填写信息,填写任务Excel中的修改内容列,如以下任务填写“业绩考核-工作量管理”,如果发生修改再次提交,在其后加上修改原因,例“业绩 ...