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 lcm(a,b)=y ,如果a,b交换位置就是不同的数对
思路:
根据lcm(最小公倍数) 的定义 y=a*b/x; 也就是说 x∗y=a∗b ;
那么 ,我们发现a,b一定为y的因数,所以我们枚举y的每个因子就可以,我们只要用log(y)的复杂度暴力算每一个因数就可以 ,
然后对于每个因子当做a, b=x*y/a; 然后判断a,b是否在区间内,gcd(a,b)是否为x,(注意要判断是否等于b)
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxm=1e6+;
const int maxn=1e5+;
using namespace std; LL gcd(LL a,LL b)
{
return b? gcd(b,a%b):a;
} int main()
{
int l,r,x,y;
scanf("%d %d %d %d",&l,&r,&x,&y);
int ans=;
for(LL i=;i*i<=y;i++)//第一个因子
{
if(y%i==)
{
LL j=x*(y/i);
if(i>=l&&i<=r&&j>=l&&j<=r&&gcd(i,j)==x)
ans++;
LL ii=y/i;//对应的另一个因子
if(i!=ii)
{
LL jj=x*(y/ii);
if(ii>=l&&ii<=r&&jj>=l&&jj<=r&&gcd(ii,jj)==x)
ans++;
}
}
}
printf("%d\n",ans);
return ;
}
Hankson的趣味题
Description
Input
接下来的n 行每 行一组输入数据,为四个正整数a0,a1,b0,b1,每两个整数之间用一个空格隔开。输入 数据保证a0 能被a1 整除,b1 能被b0 整除。
Output
对于每组数据:若不存在这样的 x,请输出0; 若存在这样的 x,请输出满足条件的x 的个数;
Sample Input
2
41 1 96 288
95 1 37 1776
Sample Output
6
2
HINT
样例说明
第一组输入数据,x 可以是9、18、36、72、144、288,共有6 个。
第二组输入数据,x 可以是48、1776,共有2 个。
数据规模和约定
对于 50%的数据,保证有1≤a0,a1,b0,b1≤10000 且n≤100。
对于 100%的数据,保证有1≤a0,a1,b0,b1≤2,000,000,000 且n≤2000。


题解:
https://www.cnblogs.com/five20/p/8434085.html
代码如下(无优化):
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxn=1e5+;
using namespace std; LL gcd(LL a,LL b)
{
if(b==) return a;
else return gcd(b,a%b);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
LL a,b,c,d;
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
if(a%b||d%c||d%b)
printf("0\n");
else
{
int num=;
for(int x=;x*x<=d;x++)
{
if(d%x==)
{
if(x%b==&&gcd(x/b,a/b)==&&gcd(d/x,d/c)==) num++;
int y=d/x;
if(x==y) continue;
if(y%b==&&gcd(y/b,a/b)==&&gcd(d/y,d/c)==) num++;
}
}
printf("%d\n",num);
}
}
return ;
}
CodeForces 992B Nastya Studies Informatics + Hankson的趣味题(gcd、lcm)的更多相关文章
- 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 ...
- CF992B Nastya Studies Informatics 数学(因子) 暴力求解 第三道
Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input st ...
- 算法训练 Hankson的趣味题
算法训练 Hankson的趣味题 时间限制:1.0s 内存限制:64.0MB 问题描述 Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Han ...
- 1172 Hankson 的趣味题[数论]
1172 Hankson 的趣味题 2009年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Descrip ...
- 1172 Hankson 的趣味题
1172 Hankson 的趣味题 2009年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Descrip ...
- Codevs 1172 Hankson 的趣味题 2009年NOIP全国联赛提高组
1172 Hankson 的趣味题 2009年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Hanks 博 ...
- 一本通1626【例 2】Hankson 的趣味题
1626:[例 2]Hankson 的趣味题 题目描述 Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson 正在思考 ...
- 洛谷 P1072 Hankson 的趣味题 解题报告
P1072 \(Hankson\)的趣味题 题目大意:已知有\(n\)组\(a0,a1,b0,b1\),求满足\((x,a0)=a1\),\([x,b0]=b1\)的\(x\)的个数. 数据范围:\( ...
随机推荐
- JSTL与EL表达式(为空判断)
JSTL与EL表达式(为空判断) 一.循环遍历集合 1.在jsp中引入标准函数声明 <%@ taglib uri="http://java.sun.com/jsp/jstl/cor ...
- 使用openssl做CA服务器,并且生成证书。
[root@22 conf.d]# openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096 #ca私钥 [root@22 conf.d]# op ...
- LIS是什么?【质量控制】
继续[LIS是什么?]中提到的[质量控制]. Ⅱ.质量控制要求非常专业,现在只说一说个人理解,以下仅为LIS检验中部分理解,实际上实验室质量控制还包含的报告时效,实验室温度.湿度等等一系列内容,是一个 ...
- 寒假day24
数据挖掘得继续深入,人物画像需要进行更多层次的分析
- XML--XML概览
参考 https://www.cnblogs.com/fangjian0423/p/xml-namespace.html http://www.w3school.com.cn/x.asp xmlns ...
- 利用mysecureshell搭建sftp服务
1.下载对应的mysecureshell-1.33-1.x86_64.rpm包 2.安装mysecureshell-1.33-1.x86_64.rpm 3.添加ftp用户 useradd ftp 4. ...
- [tensorflow] 线性回归模型实现
在这一篇博客中大概讲一下用tensorflow如何实现一个简单的线性回归模型,其中就可能涉及到一些tensorflow的基本概念和操作,然后因为我只是入门了点tensorflow,所以我只能对部分代码 ...
- 使用Map,统计字符串中每个字符出现的次数
package seday13; import java.util.HashMap; import java.util.Map; /** * @author xingsir * 统计字符串中每个字符出 ...
- vivado下创建基本时序周期约束
创建基本时钟周期约束.(验证我们的设计能否在期望的频率上运行) (学习记录,晚一点会做实验传上来的.) 时钟基本概念:https://blog.csdn.net/wordwarwordwar/arti ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:计时事件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...