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 ...
随机推荐
- 面试题_Spring基础篇
Spring基础题 1. 什 么 是 Spring? Spring 是 个 java 企 业 级 应 用 的 开 源 开 发 框 架 .Spring 主 要 用 来 开 发 Java 应 用 , 但 ...
- Robot Framework(七)创建用户关键字
2.6创建用户关键字 关键字表用于通过将现有关键字组合在一起来创建新的更高级别关键字.这些关键字称为用户关键字,以区别于 测试库中实现的最低级库关键字.创建用户关键字的语法与创建测试用例的语法非常接近 ...
- Java图片裁剪
public static void main(String[] args) throws IOException { String path = "C:/Users/yang/Deskto ...
- Linux设备驱动程序 之 open和release
open方法 open方法提供给驱动程序以初始化的能力,在大部分驱动程序汇总,open应该完成以下工作: 1. 检查特定设备的错误,如设备为准备就绪或者硬件问题: 2. 如果设备是首次打开,则对其进行 ...
- LeetCode 128. 最长连续序列(Longest Consecutive Sequence)
题目描述 给定一个未排序的整数数组,找出最长连续序列的长度. 要求算法的时间复杂度为 O(n). 示例: 输入: [100, 4, 200, 1, 3, 2] 输出: 4 解释: 最长连续序列是 [1 ...
- <HTML>在一个表格内嵌套另一个表格时,如何居中?
在一个表格内嵌套另一个表格时,如何居中? 假设大表格为: <table id="tableRow"> <tr> <th>City</th& ...
- LC 351. Android Unlock Patterns
Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total ...
- UDDI:百科
ylbtech-UDDI:百科 UDDI是一种用于描述.发现.集成Web Service的技术,它是Web Service协议栈的一个重要部分.通过UDDI,企业可以根据自己的需要动态查找并使用Web ...
- 003-tomcat配置文件-server、tomcat-users
1.server.xml讲解 位于conf下 <?xml version="1.0" encoding="UTF-8"?> <!-- Serv ...
- MySQL数据库同步工具的设计与实现
一.背景 在测试过程中,对于不同的测试团队,出于不同的测试目的,我们可能会有多套测试环境.在产品版本迭代过程中,根据业务需求,会对数据库的结构进行一些修改,如:新增表.字段.索引,修改表.字段索引等操 ...