类型:数论

传送门:>Here<

题意:给出四个数$a_0,a_1,b_0,b_1$,求满足$gcd(x,a_0)=a_1,lcm(x,b_0)=b_1$的$x$的个数

解题思路

显然$a_1 | x, x|b_1$,因此设$x = a_1 * p, \ b_1 = x*q$。则$b_1 = a_1*p*q$

设$p*q=b_1/a_1=s$

$∵gcd(x,a_0)=a_1 \ ∴gcd(x/a_1,a_0/a_1)=1$

$∵lcm(x,b_0)=b_1 \ ∴gcd(b_1/x,b_1/b_0)=1$

由于$x/a_1=p,b_1/x=q=s/p$

$∴ \left\{\begin{matrix} gcd(p,a_0/a_1)=1\\ gcd(s/p,b_1/b_0)=1\\ \end{matrix}\right. $

由此我们发现,只需要枚举$s$的因子$p$进行验证即可,复杂度$O(\sqrt{s} * N)$

Code

特判完全平方数

/*By DennyQi 2018.8.17*/
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
#define r read()
#define Max(a,b) (((a)>(b)) ? (a) : (b))
#define Min(a,b) (((a)<(b)) ? (a) : (b))
using namespace std;
typedef long long ll;
const int MAXN = ;
const int MAXM = ;
const int INF = ;
inline int read(){
int x = ; int w = ; register int c = getchar();
while(c ^ '-' && (c < '' || c > '')) c = getchar();
if(c == '-') w = -, c = getchar();
while(c >= '' && c <= '') x = (x<<) + (x<<) + c - '', c = getchar();return x * w;
}
int n,m,a[],b[],p,s,T,lim,ans;
int gcd(int a, int b){
return !b ? a : gcd(b, a%b);
}
inline bool judge(int s, int p){
if(gcd(s/p, b[]/b[]) != ) return ;
if(gcd(p, a[]/a[]) != ) return ;
return ;
}
int main(){
T = r;
while(T--){
a[] = r, a[] = r;
b[] = r, b[] = r;
s = b[] / a[];
ans = ;
lim = floor(sqrt(s));
for(p = ; p <= lim; ++p){
if(s % p == ){
if(judge(s,p)) ++ans;
if(s/p == p) continue;
if(judge(s,s/p)) ++ans;
}
}
printf("%d\n", ans);
}
return ;
}

[NOIp2009] $Hankson$ 的趣味题的更多相关文章

  1. 洛谷P1072 [NOIP2009] Hankson 的趣味题

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

  2. NOIP2009 Hankson 的趣味题 : 数论

    题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上,老师讲解 ...

  3. NOIP2009 Hankson的趣味题

    题目描述 Description Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson 正在思考一个有趣的问题.今天在 ...

  4. [NOIP2009] $Hankson$ 的趣味题 (数论,gcd)

    题目链接 Solution 此题,用到的结论都是比较浅显的,但是,我竟然没想到反过来枚举... 只有50分... 被自己蠢哭... 结论比较浅显: 1.对于两个正整数\(a\),\(b\),设 \(g ...

  5. luogu1072 [NOIp2009]Hankson的趣味题 (数学+STL::set)

    一个JSB做法 由$\frac{x*b0}{gcd(x,b0)}=b1$,可得$\frac{x}{gcd(x,b0)}=\frac{b1}{b0}$ 设$b2=\frac{b1}{b0}$ 所以对$b ...

  6. NOIP 2009 Hankson 的趣味题

    洛谷 P1072 Hankson 的趣味题 洛谷传送门 JDOJ 1648: [NOIP2009]Hankson的趣味题 T2 JDOJ传送门 Description Hanks 博士是BT (Bio ...

  7. 「NOIP2009」Hankson 的趣味题

    Hankson 的趣味题 [内存限制:$128 MiB$][时间限制:$1000 ms$] [标准输入输出][题目类型:传统][评测方式:文本比较] 题目描述 Hanks 博士是 BT(Bio-Tec ...

  8. CH3201 Hankson的趣味题

    题意 3201 Hankson的趣味题 0x30「数学知识」例题 描述 Hanks博士是BT(Bio-Tech,生物技术)领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson ...

  9. 算法训练 Hankson的趣味题

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

随机推荐

  1. 【fetch跨域请求】cors

    当使用fetch 发起跨域请求时,CORS(跨域资源共享Cross-origin resource sharing) 请求fetch const body = {name:"Good boy ...

  2. 新浪2017校园招聘---C++后台研发

    一共10道题目,难度不大,就是题量大,时间短. 1.  编程        写一个函数,求出一字符串的所有排列. 2.  编程        实现一个在32位系统下把字符串转换成浮点数的函数 floa ...

  3. Python-每日习题-0009-time

    题目:暂停一秒输出 程序分析:使用 time 模块的 sleep() 函数. import time for i in range(4): print(str(int(time.time()))[-2 ...

  4. matplotlib 入门之Usage Guide

    文章目录 Usage Guide plotting函数的输入 matplotlib, pyplot, pylab, 三者的联系 Coding style Backends 后端 matplotlib教 ...

  5. 1060E Sergey and Subway(思维题,dfs)

    题意:给出一颗树,现在,给哪些距离为2的点对,加上一条边,问所有点对的距离和 题解:如果没有加入新的边,距离和就会等于每条边的贡献,由于是树,我们用点来代表点上面的边,对于每条边,它的贡献将是(子树大 ...

  6. Array Division CodeForces - 808D (构造+实现)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  7. Elasticsearch - 简单介绍

    Elasticsearch 简介 1. 什么是 Elasticsearch ElasticSearch 是一个基于 Lucene 的搜索服务器. 它了一个分布式多 用户能力的全文搜索引擎,能够达到实时 ...

  8. Git push提交时报错Permission denied(publickey)...Please make sure you have the correct access rights and the repository exists.

    一.git push origin master 时出错 错误信息为: Permission denied(publickey). fatal: Could not read from remote ...

  9. [转帖]SAP一句话入门:Finacial & Controlling Accounting

    SAP一句话入门:Finacial & Controlling Accounting http://blog.vsharing.com/MilesForce/A621147.html 财务,财 ...

  10. Linux安装mysql5.6

    安装mysql5.6https://www.cnblogs.com/wangdaijun/p/6132632.html