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 ...
随机推荐
- vue-cli 本地代理 造成session丢失 而登录不上去 解决办法
本地代理造成session丢失,登录不成功,是由于代理配置造成的 devServer: { port: 8000, proxy:{ '/qiantai':{ target:'线上地址/qiantai' ...
- jmeter从文件中读取参数,并实现循环
1. 通过BeanShell Sampler获取csv的行数 import java.io.BufferedReader;import java.io.FileReader;BufferedReade ...
- JVM——内存结构
一.程序计数器/PC寄存器 (Program Counter Registe) 用于保存当前正在执行的程序的内存地址(下一条jvm指令的执行地址),由于Java是支持多线程执行的,所以程序执行的轨迹不 ...
- Postman官方文档翻译
本文根据官方文档,为千夜同学的翻译做了一个目录 启动Postman Postman的安装和升级 发送第一个请求 创建第一个集合 Postman导航 Postman账号 同步 设置 新按钮 发送API请 ...
- 第三章 python数据规整化
本章概要 1.去重 2.缺失值处理 3.清洗字符型数据的空格 4.字段抽取 去重 把数据结构中,行相同的数据只保留一行 函数语法: drop_duplicates() #导入pandas包中的read ...
- CPU分支预测器
两篇结合就ok啦 1.https://www.jianshu.com/p/be389eeba589 2.https://blog.csdn.net/edonlii/article/details/87 ...
- DataFactory生产手机号码
表中的数据类型是CHAR()类型的,才会出现,如右图的“Build a composite field”的这个功能: 固定部分设置 剩余变化部分设置 操作成功 数据库查询的结果
- 动态库(.so)隐藏函数名
一.偶遇 error: undefined reference to xxx 问题 尝试封装通用的接口到一个private.so,然后供客户端使用,private.so编译出来后由sample.cp ...
- DML语句
DML 操作是指对数据库中表记录的操作,主要包括表记录的插入(insert).更新(update).删除(delete)和查询(select),是开发人员日常使用最频繁的操作. 插入记录 表创建好后, ...
- Ubuntu14.04+安卓系统4.3+JDK6编译源码
本博客主要参照: https://www.jianshu.com/p/ecb9c132030f https://blog.csdn.net/gobitan/article/details/243674 ...