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\)的个数. 数据范围:\( ...
随机推荐
- easyUI中,z-index失效问题
1.z-index是css的属性,第一种div设置css的z-index时,是不起作用的,最后设置在style中才起作用了,比较诡异的一件事情. 2.还有一种情况就是,遮盖层在dialog弹出层的下面 ...
- 安装与配置windbg的symbol(符号)
http://msdn.microsoft.com/en-us/windows/hardware/gg463028.aspx windows symbols下载地址 本篇是新手自己写的一点心得.建议 ...
- 【pwnable.kr】 flag
pwnable从入门到放弃 第四题 Download : http://pwnable.kr/bin/flag 下载下来的二进制文件,对着它一脸懵逼,题目中说是逆向题,这我哪会啊... 用ida打开看 ...
- 总结不进入Mysql,执行Mysql命令的5种方法
不进入mysql,执行mysql命令 直接使用-e 命令 mysql -u root -p xxxxxx -e "show databases;" 使用eof写入命令 mysql ...
- psp --2
PSP0 ---2 项目计划日志 姓名:赵腾 日期:9/12/2017 任务 日期 听课 编写程序 阅读课 ...
- 79.常用的返回QuerySet对象的方法使用详解: filter, exclude,annotate
返回新的QuerySet的常用方法: 1.filter: 将满足条件的数据提取出来,返回一个新的QuerySet 以下所使用的模型article,category,定义模型models.py文件中,示 ...
- dac FDMemTable
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...
- CodeForces 1000C Covered Points Count(区间线段覆盖问题,差分)
https://codeforces.com/problemset/problem/1000/C 题意: 有n个线段,覆盖[li,ri],最后依次输出覆盖层数为1~n的点的个数. 思路: 区间线段覆盖 ...
- 题解 P1019 【单词接龙】
题目 单词具体是什么不重要,知道单词间如何转化即可 [分析] 先理清一下题意: \(n\)个单词,每个单词限用两次 上一个单词能与下一个单词接上,当且仅当上一个单词的末尾 \(k\) 个字符与下一个单 ...
- SQL基础教程(第2版)第2章 查询基础:练习题
SELECT product_name, regist_date FROM Product WHERE regist_date > '2009-04-28'; ① ~ ③中的 SQL 语句都无法 ...