GCD and LCM HDU 4497 数论

题意

给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能。注意123和321算两种情况。

解题思路

L代表LCM,G代表GCD。

\[x=(p_1^{i_1})*(p_2^{i_2})*(p_3^{i_3})\dots
\]

\[y=(p_1^{j_1})*(p_2^{j_2})*(p_3^{j_3})\dots
\]

\[z=(p_1^{k_1})*(p_2^{k_2})*(p_3^{k_3})\dots
\]

\[G=(p_1^{m_1})*(p_2^{m_2})*(p_3^{m_3})\dots
\]

\[L=(p_1^{n_1})*(p_2^{n_2})*(p_3^{n_3})\dots
\]

m是i j k 中得最小值,n是i j k中得最大值。

那么L/G得

\[L/G=(p_1^{r_1})*(p_2^{r_2})*(p_3^{r_3})\dots
\]

\[x/G=(p_1^{a_1})*(p_2^{a_2})*(p_3^{a_3})\dots
\]

\[y/G=(p_1^{b_1})*(p_2^{b_2})*(p_3^{b_3})\dots
\]

\[z/G=(p_1^{c_1})*(p_2^{c_2})*(p_3^{c_3})\dots
\]

那么 \(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 数论的更多相关文章

  1. GCD and LCM HDU - 4497(质因数分解)

    Problem Description Given two positive integers G and L, could you tell me how many solutions of (x, ...

  2. 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都可以写成 ...

  3. HDU 4497 数论+组合数学

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...

  4. HDU 4497 GCD and LCM(数论+容斥原理)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  5. 数论——算数基本定理 - HDU 4497 GCD and LCM

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  6. 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 ...

  7. HDU 4497 GCD and LCM (合数分解)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  8. hdu 4497(排列组合+LCM和GCD)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  9. hdu 4497 GCD and LCM (非原创)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

随机推荐

  1. git log 详解 以及代码量统计

    https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86% ...

  2. vue token 过期处理

    1.登陆成功后储存token  可以利用 vuex 储存token 2.利用路由守卫处理 router.beforeEach((to, from, next) => {   })     3.我 ...

  3. Maven高级

    第一章 Maven解决冲突的方式 1.1 第一声明者优先原则 那个jar包的坐标在pom.xml文件上属于靠上的位置,这个jar包就是先声明的.先声明的jar包坐标下的依赖包,可以优先进入项目中. 示 ...

  4. spring security基本知识(二) 自定义认证

    配置自定义的用户存储 我们在 SecurityConfig 的配置类中 重写了 configure(AuthenticationManagerBuilder auth) 方法,我们可以通过 Authe ...

  5. IDEA maven 配置,运行比较慢,加截本地仓库资源数据

    在 Runner 配置了参数: -DarchetypeCatalog=internal

  6. sh_02_第2个Python程序

    sh_02_第2个Python程序 print("hello")

  7. activeMQ安全机制

  8. TYPORA的使用手册

    Typora可以根据当前文档的标题层级,自动生成并显示大纲,窗口的右下角并有字数显示. 1.标题的使用标题的使用格式# 一阶标题 或者快捷键Ctrl+1 ##二阶标题 或者快捷键Ctrl+2 ###三 ...

  9. spring util包 StringUtils工具类中的isEmpty() 方法解析

    今天在公司看到同事写的代码,无意发现在判断字符串类型时,使用的是StringUtils工具类中的isEmpty()去判断如下所示 @RequestMapping(value = "/pub/ ...

  10. 微信小程序之登录用户不是该小程序的开发者

    当uniapp项目转为小程序项目的时候,预览会显示“您不是登录用户...”,所以没有办法发布,这个时候打开“project.config.json”设置一下appid,与你公众号appid一致就可以