GCD and LCM HDU - 4497(质因数分解)
Problem Description
Note, gcd(x, y, z) means the greatest common divisor of x, y and z, while lcm(x, y, z) means the least common multiple of x, y and z.
Note 2, (1, 2, 3) and (1, 3, 2) are two different solutions.
Input
First line comes an integer T (T <= 12), telling the number of test cases. The next T lines, each contains two positive 32-bit signed integers, G and L. It’s guaranteed that each answer will fit in a 32-bit signed integer.
Output
For each test case, print one line with the number of solutions satisfying the conditions above.
Sample Input
6
Sample Output
72
0 大概题意: 给出T组数据每组数据有两个数分别为x,y,z的最大公约数和
最小公倍数,让我们求出x,y,z总共有多少组不同组合方式; 具体思路:
#include<iostream>
using namespace std;
#define N 100100
#define ll long long
ll d[N][],e[N][],cntn,cntm;
void devide(int n,int m)
{
cntn=cntm=;
for(int i=;i*i<=n;i++)
{
if(n%i==)
{
int num=;
while(n%i==)
{
num++;
n/=i;
}
d[++cntn][]=i,d[cntn][]=num;
}
}
for(int i=;i*i<=m;i++)
{
if(m%i==)
{
int num=;
while(m%i==)
{
num++;
m/=i;
}
e[++cntm][]=i,e[cntm][]=num;
}
}
if(n>)d[++cntn][]=n,d[cntn][]=;
if(m>)e[++cntm][]=m,e[cntm][]=;
}
ll solve(int n,int m)
{
if(m%n!=)
return ;
devide(n,m);
ll ans=,v;
for(int i=;i<=cntm;i++)
{
int flag=;
for(int j=;j<=cntn;j++)
if(e[i][]==d[j][])
{
flag=;
v=j;
break;
}
if(!flag)
ans=ans**e[i][];
else
{
ll t=e[i][]-d[v][];
if(t==)continue;
ans=ans**t;
}
}
return ans;
}
int main()
{
int t;
int n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
ll ans=solve(n,m);
cout<<ans<<endl;
}
return ;
}
实践是检验真理的唯一标准;
GCD and LCM HDU - 4497(质因数分解)的更多相关文章
- GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...
- 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 1045(质因数分解)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Tomor ...
- HDU 1695 GCD 欧拉函数+容斥原理+质因数分解
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:在[a,b]中的x,在[c,d]中的y,求x与y的最大公约数为k的组合有多少.(a=1, a ...
- G - GCD and LCM 杭电
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, sa ...
- 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 (数学,质数分解)
题意:给定G,L,分别是三个数最大公因数和最小公倍数,问你能找出多少对. 析:数学题,当时就想错了,就没找出规律,思路是这样的. 首先G和L有公因数,就是G,所以就可以用L除以G,然后只要找从1-(n ...
- hdu 4497 GCD and LCM 质因素分解+排列组合or容斥原理
//昨天把一个i写成1了 然后挂了一下午 首先进行质因数分解g=a1^b1+a2^b2...... l=a1^b1'+a2^b2'.......,然后判断两种不可行情况:1,g的分解式中有l的分解式中 ...
- 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 ...
随机推荐
- Dubbo 节点telnet测试
Dubbo 节点telnet测试 本地安装telnet客户端 Telnet 服务地址 端口 如telnet 127.0.0.1 1234 出现此对话框表示连接成功 输入status –l 会显 ...
- Java并发指南开篇:Java并发编程学习大纲
Java并发编程一直是Java程序员必须懂但又是很难懂的技术内容. 这里不仅仅是指使用简单的多线程编程,或者使用juc的某个类.当然这些都是并发编程的基本知识,除了使用这些工具以外,Java并发编程中 ...
- centos 安装mariadb 替代mysql
yum install mariadb-server mariadb systemctl start mariadbmysql -uroot -p默认密码mysql -uroot -pmysql_se ...
- Flume-日志聚合
Flume-1 监控文件 /tmp/tomcat.log. Flume-2 监控某一个端口的数据流. Flume-1 与 Flume-2 将数据发送给 Flume-3,Flume-3 将最终数据打印到 ...
- Docker Image
Docker 对 container 的使用基本是建立在 LXC 基础之上,然而 LXC 存在的问题是难以移动,难以通过标准化的模板去制作.重建.复制和移动 container. 在以 VM 为基础的 ...
- pytorch-mnist神经网络训练
在net.py里面构造网络,网络的结构为输入为28*28,第一层隐藏层的输出为300, 第二层输出的输出为100, 最后一层的输出层为10, net.py import torch from torc ...
- SQL-W3School-基础:SQL 语法
ylbtech-SQL-W3School-基础:SQL 语法 1.返回顶部 1. 数据库表 一个数据库通常包含一个或多个表.每个表由一个名字标识(例如“客户”或者“订单”).表包含带有数据的记录(行) ...
- C# WPF ASP.net 上传多文件和数据
C# WinForm 上传多文件和数据 public static class HttpHelper { private static readonly Encoding DEFAULTENCODE ...
- keepalived+LVS-DR集群
一.Keepalived介绍 keepalived 是一个类似于 layer3, 4 & 5 交换机制的软件,也就是我们平时说的第 3 层.第 4 层和第 5层交换. Keepalived 的 ...
- partprobe 和 partx 的用法
partprobe: 用于重读分区表,当出现删除文件后,出现仍然占用空间.可以partprobe在不重启的情况下重读分区. 将磁盘分区表变化信息通知内核,请求操作系统重新加载分区表. -d 不更新内核 ...