GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论
题意
给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能。注意123和321算两种情况。
解题思路
L代表LCM,G代表GCD。
\]
\]
\]
\]
\]
m是i j k 中得最小值,n是i j k中得最大值。
那么L/G得
\]
\]
\]
\]
那么 \(a\) \(b\) \(c\) 中一定有一个是 \(r\) ,也一定有一个是 \(0\) 为什么呢?因为x, y, z 分别处以最大公约数后,指数就相应的减少了,这样就会使得a, b, c,中有一个是0。
这样a,b, c,中就有三种情况。
r, 0, 0, C(3, 1)三种
r, 0, r,C(3, 1)三种
r, 0, 1~r-1 有(r-1)*A(3, 3)
有6*r种,
代码实现
/*15ms,200KB*/
#include<cstdio>
int main()
{
int t;
long long m, n, ans, i, count;
scanf("%d", &t);
while (t--)
{
scanf("%I64d%I64d", &m, &n);
if (n % m) puts("0");///注意特判
else
{
n /= m;
ans = 1;
for (i = 2; i * i <= n; i += 2)///不用求素数,因为范围很小(注意n在不断减小)
{
if (n % i == 0)
{
count = 0;
while (n % i == 0)
{
n /= i;
++count;
}
ans *= 6 * count;
}
if (i == 2)
--i;///小技巧
}
if (n > 1) ans *= 6;
printf("%I64d\n", ans);
}
}
return 0;
}
GCD and LCM HDU 4497 数论的更多相关文章
- GCD and LCM HDU - 4497(质因数分解)
Problem Description Given two positive integers G and L, could you tell me how many solutions of (x, ...
- GCD and LCM HDU - 4497
题目链接:https://vjudge.net/problem/HDU-4497 题意:求有多少组(x,y,z)满足gcd(x,y,z)=a,lcm(x,y,z)=b. 思路:对于x,y,z都可以写成 ...
- HDU 4497 数论+组合数学
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...
- HDU 4497 GCD and LCM(数论+容斥原理)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- 数论——算数基本定理 - HDU 4497 GCD and LCM
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- hdu 4497 GCD and LCM 数学
GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...
- HDU 4497 GCD and LCM (合数分解)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- hdu 4497(排列组合+LCM和GCD)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- hdu 4497 GCD and LCM (非原创)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
随机推荐
- jvm slot复用
如果当前字节码PC计数器的值已经超出了某个变量的作用域,那这个变量对应的Slot就可以交给其他变量使用. 字节码PC计数器就是程序计数器,程序计数器记录当前线程所执行的字节码的偏移地址.如果这个值超出 ...
- python-上传文件的几种方式
from requests_toolbelt import MultipartEncoder import requests # from_data上传文件,注意参数名propertyMessageX ...
- 事物 @Transactional
转载:http://www.cnblogs.com/kristain/articles/2038397.html 一.什么是事务 事务是访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数据库 ...
- android 开发架构学习
Android DataBinding(数据绑定)入门与实战 http://examplecode.cn/2018/07/20/android-databinding-01-introduction/ ...
- CopyOnWrite 个人理解以及应用
缘由 最近在看<Redis 设计与实现>,看到Redis的执行bgsave生成dump.rdb是根据CopyOnWrite的 之前也不是很懂为啥要有CopyOnWrite这个东西 翻看文章 ...
- mysqldump mysql数据库导入导出
syhuo_oauth数据库结构 [root@VM_58_118_centos dbback]# /usr/bin/mysqldump -uroot -P3306 --protocol=tcp --h ...
- Internet History, Technology, and Security(week5)——Technology: Internets and Packets
前言: 之前都在学习Internet的历史,从这周开始,进入到了Internet技术的学习. Layer1: Link Introduction / The Link Layer 80年代之前,主流网 ...
- Sign on Fence(连续的长为W的一段中最小的数字的最大值)
题目链接:http://codeforces.com/problemset/problem/484/E 题意:给你个n,n个木板都有高度,宽度都为1 ,给你两个数[l,r]和一个w,求在[l,r]区间 ...
- Android单行跑马灯效果实现
参考网址:https://www.jianshu.com/p/e6c1b825d322 起初,使用了如下XML布局: <TextView android:id="@+id/tv_per ...
- Oracle 10046 event
http://czmmiao.iteye.com/blog/1497509 10046事件概述Oracle的10046事件,可以跟踪应用程序所执行的SQL语句,并且得到其解析次数.执行次数,CPU使用 ...