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

  Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson。现 在,刚刚放学回家的Hankson 正在思考一个有趣的问题。 今天在课堂上,老师讲解了如何求两个正整数c1 和c2 的最大公约数和最小公倍数。现 在Hankson 认为自己已经熟练地掌握了这些知识,他开始思考一个“求公约数”和“求公 倍数”之类问题的“逆问题”,这个问题是这样的:已知正整数a0,a1,b0,b1,设某未知正整 数x 满足: 1. x 和a0 的最大公约数是a1; 2. x 和b0 的最小公倍数是b1。 Hankson 的“逆问题”就是求出满足条件的正整数x。但稍加思索之后,他发现这样的 x 并不唯一,甚至可能不存在。因此他转而开始考虑如何求解满足条件的x 的个数。请你帮 助他编程求解这个问题。

Input

  输入第一行为一个正整数n,表示有n 组输入数据。
接下来的n 行每 行一组输入数据,为四个正整数a0,a1,b0,b1,每两个整数之间用一个空格隔开。输入 数据保证a0 能被a1 整除,b1 能被b0 整除。

Output

  输出共n 行。每组输入数据的输出结果占一行,为一个整数。
对于每组数据:若不存在这样的 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)的更多相关文章

  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. CF992B Nastya Studies Informatics 数学(因子) 暴力求解 第三道

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

  4. 算法训练 Hankson的趣味题

    算法训练 Hankson的趣味题   时间限制:1.0s   内存限制:64.0MB        问题描述 Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Han ...

  5. 1172 Hankson 的趣味题[数论]

    1172 Hankson 的趣味题 2009年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Descrip ...

  6. 1172 Hankson 的趣味题

    1172 Hankson 的趣味题 2009年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Descrip ...

  7. Codevs 1172 Hankson 的趣味题 2009年NOIP全国联赛提高组

    1172 Hankson 的趣味题 2009年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Hanks 博 ...

  8. 一本通1626【例 2】Hankson 的趣味题

    1626:[例 2]Hankson 的趣味题 题目描述 Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson 正在思考 ...

  9. 洛谷 P1072 Hankson 的趣味题 解题报告

    P1072 \(Hankson\)的趣味题 题目大意:已知有\(n\)组\(a0,a1,b0,b1\),求满足\((x,a0)=a1\),\([x,b0]=b1\)的\(x\)的个数. 数据范围:\( ...

随机推荐

  1. 5 ~ express ~ 连接数据库

    1, 在schema 目录创建 users.js 文件,通过 mongoose 模块来操作数据库 2,  在定义 users 表结构之前,需要让应用支持或连接数据库 . 所以要在应用的入口文件 app ...

  2. SpringBoot基于easyexcel导出和写入Excel

      easyexcel是阿里巴巴旗下开源项目,主要用于Excel文件的导入和导出处理,今天我们利用SpringBoot和easyexcel实战演示如何导出和写入Excel文件. 一.加入我们需要的ea ...

  3. .NET CORE AutoMapper使用

    1.通过nuget安装AutoMapper,版本是7.0.1, 安装AutoMapper.Extensions.Microsoft.DependencyInjection  版本是4.0.1 不是以上 ...

  4. JVM探秘:MAT分析内存溢出

    本系列笔记主要基于<深入理解Java虚拟机:JVM高级特性与最佳实践 第2版>,是这本书的读书笔记. MAT是分析Java堆内存的一个工具,全称是 The Eclipse Memory A ...

  5. 实验吧Web-难-猫抓老鼠

    看题目好像就有让我们抓包的意思. 不管输什么走势一个结果:Check Failed! 也用bp爆破了,但是出不来什么结果. 抓到包后,送到repeater中go一下,发现有一串base64码,以为解码 ...

  6. mysql初始化出现:FATAL ERROR: Neither host 'DB01' nor 'localhost' could be looked up with

    初始化时: FATAL ERROR: Neither host 'DB01' nor 'localhost' could be looked up with /application/mysql/bi ...

  7. linux部分环境搭建

    连接数据库: mysql -hrm-uf6b23117l3s5t69zjo.mysql.rds.aliyuncs.com -uwswl -pwswl@2019 显示用户: show databases ...

  8. Codeforces Round #604 (Div. 2) 部分题解

    链接:http://codeforces.com/contest/1265 A. Beautiful String A string is called beautiful if no two con ...

  9. JZOJ-2019-11-5 A组

    T1 给定由 n 个点 m 条边组成的无向连通图,保证没有重边和自环. 你需要找出所有边,满足这些边恰好存在于一个简单环中.一个环被称为简单环,当且仅当它包含的所有点都只在这个环中被经过了一次.(即求 ...

  10. 高级变量类型(列表,元组,字典,字符串,公共方法,变量高级)for循环

    Python 中数据类型可以分为 数字型 和 非数字型 数字型 整型 (int) 浮点型(float) 布尔型(bool) 真 True 非 0 数 -- 非零即真 假 False 0 复数型 (co ...