题意:

给两个数,lll 和 ggg,为x , y , z,的最小公倍数和最大公约数,求出x , y , z 的值有多少种可能性

思路:

将x , y , z进行素因子分解

素因子的幂次
x a1 a2 a3 a4
y b1 b2 b3 b4
z c1 c2 c3 c4
gcd min(a1,b1,c1) min(a2,b2,c3)…
lcm max(a1,b1,c1) max(a2,b2,c3)…

第一组样例:

6=21 * 31

72= 23 * 32

最大公约数和最小公倍数约分得 12=22 * 31(是否约分并不重要,幂次相减就可以了),设最大公约数为1,最小公倍数为12

设 x为1 ,y=12,也就是

素因子的幂次
x a1=0, a2 =0
y b1 = 2 , b2=1
z c1=0~2 , c2= 0~1

将素因子按列对齐,当出现两个幂次相等时,排列组合为3,当三个幂次都不相等时,排列组合为6,

上述例子c1的范围是0~2,当c1=0和c1=2时合并为1个6,所以是2 * 6,c2=1和c2=0合并为一个6,所以是1 * 6,根据两个素因子相乘,得出2* 6 * 1*6。

#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
using namespace std;
int main()
{ int t,n,m,g,l,acc;
scanf("%d",&t);
while(t--)
{
struct
{
vector<int>e;
map<int,int>mp;
} gcd,lcm; scanf("%d%d",&g,&l);
if(l%g)//一组数的最大公约数和最小公倍数肯定能整除
{
printf("0\n");
continue;
}
acc=l/g;
int ans=1;
for(int i=2;; i++)
{
if(acc%i==0)
{
int t=0;
while(acc%i==0)
{
acc=acc/i;
t++;
}
ans=ans*6*t;
}
if(acc==1)
break;
}
printf("%d\n",ans);
}
return 0;
}

HDU 4497 GCD and LCM 素因子分解+ gcd 和 lcm的更多相关文章

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

  2. HDU 4497 GCD and LCM(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

  3. GCD and LCM HDU 4497 数论

    GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...

  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 (数论)

    题意:三个数x, y, z. 给出最大公倍数g和最小公约数l.求满足条件的x,y,z有多少组. 题解:设n=g/l n=p1^n1*p2^n2...pn^nk (分解质因数 那么x = p1^x1 * ...

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

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

  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. GCD and LCM HDU - 4497(质因数分解)

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

随机推荐

  1. 利用ajax 引入静态页公共的头部与底部

    利用ajax引入公共的头部与底部或者多个页面需要用到的重复的组件,对于新入门的前端来说是很实用的方法,自己也是新手菜鸟一枚,折腾了好久,实现的方法有很多种,这是我个人觉得比较简单方便的 首先得把公用的 ...

  2. 利用GitHub制作在线炫酷简历

    首先我们先体验一下炫酷简历.然后决定我们要不要使用. https://jessezhao1990.github.... 如何使用本项目部署你自己的在线简历 1. 书写简历 在src文件夹里面有个con ...

  3. Java多态实现的机制

    Java提供了编译时多态和运行时多态两种多态机制.前者是通过方法重载实现的,后者是通过方法的覆盖实现的. 在方法覆盖中,子类可以覆盖父类的方法,因此同类的方法会在父类与子类中有着不同的表现形式. 在J ...

  4. psql的jsonb操作--存储对象/对象数组

    1. 建表 create table demo( id serial NOT NULL PRIMARY KEY, name ), info JSONB ); 2.存储对象操作 2.1添加 insert ...

  5. Mac笔记本使用小道解答集

    如何设置Mac默认应用程序 https://www.jianshu.com/p/0f912e6c846c 苹果本安装微软雅黑 下载微软雅黑字体Mac版 解压.ttf 拖拽放入 我的电脑/资源库/fon ...

  6. 点云3d检测模型pointpillar

    PointPillars 一个来自工业界的模型.https://arxiv.org/abs/1812.05784 3D目标检测通常做法 3d卷积 投影到前平面 在bird-view上操作 处理思路依然 ...

  7. 报错: raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

    Django2.0同步Mysql数据库时出现的问题 执行 python manage.py makemigrations 报错 # 报错位置 File "G:\python\lib\site ...

  8. vue安卓4.4.2页面打不开的坑

    项目上线两三天,有保障说安卓下面页面打不开,所以查了下具体原因,系统版本过低,安卓4.4.2,然后发现本地没有babel-polyfill的包,具体解决方案如下: 1,npm 安装 npm insta ...

  9. php -v 找不到命令

    [root@localhost htdocs]# php -v -bash: php: command not found export PATH=$PATH:/usr/local/php7/bin ...

  10. selenium+Python 将登录模块化

      公共模块化:(登录) login.py   from selenium import webdriver from time import sleep   class login(): def u ...