题意:给定G,L,分别是三个数最大公因数和最小公倍数,问你能找出多少对。

析:数学题,当时就想错了,就没找出规律,思路是这样的。

首先G和L有公因数,就是G,所以就可以用L除以G,然后只要找从1-(n=L/G),即可,那么可以进行质因数分解,假设:

n = p1^t1*p2^t2*p3^t3;那么x, y, z,除以G后一定是这样的。

x = p1^i1*p2^i2*p3^i3;

y = p1^j1*p2^j2*p3^j3;

z = p1^k1*p2^k2*p3^k3;

那么我们可以知道,i1, j1, k1中最少一个t1,最多2个,0也是,考虑最大公因数,所以就会有下面三种方案。

0 0 t1         排列有三种

0 t1 t1        排列有三种

0 t1 1-t1-1  排列有(t1-1)*6种

所以加起来有t1*6种,那么只要找质因数的指数就好。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 56 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
int T; cin >> T;
while(T--){
int g, l;
cin >> g >> l;
if(l % g) printf("0\n");
else {
int gl = l / g;
int n = sqrt(gl+0.5);
int ans = 1;
for(int i = 2; i <= n && gl > 1; ++i){
if(gl % i == 0){
int cnt = 0;
while(gl % i == 0){
gl /= i;
++cnt;
}
ans *= cnt * 6;
}
}
if(gl != 1) ans *= 6;
cout << ans << endl;
}
}
return 0;
}

HDU 4497 GCD and 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 (合数分解)

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

  3. hdu 4497 GCD and LCM 质因素分解+排列组合or容斥原理

    //昨天把一个i写成1了 然后挂了一下午 首先进行质因数分解g=a1^b1+a2^b2...... l=a1^b1'+a2^b2'.......,然后判断两种不可行情况:1,g的分解式中有l的分解式中 ...

  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: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  7. 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,求满 ...

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

    链接 :  http://acm.hdu.edu.cn/showproblem.php?pid=4497 假设G不是L的约数 就不可能找到三个数. L的全部素因子一定包括G的全部素因子 而且次方数 ...

  9. 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 * ...

随机推荐

  1. win32窗口机制之CreateWindow

    CreateWindow     函数功能:该函数创建一个重叠式窗口.弹出式窗口或子窗口.它指定窗口类,窗口标题,窗口   风格,以及窗口的初始位置及大小(可选的).该函数也指定该窗口的父窗口或所属窗 ...

  2. 【转】strcpy溢出的攻击示例

    在学习c/c++的时候,就讲到了一些C类型的字符串函数不是安全的,比如strcpy没有检查长度会溢出,推荐使用strncpy,笔试面试也经常问到.同时经常浏览安全相关的新闻,缓冲区溢出攻击是很常见的一 ...

  3. ApplicationContext.xml 的最终xml声明,包括注解 aop

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  4. pg psql命令

    linux下使用psql命令操作数据库 下面主要用到了insert into  ,pg_dump  , pg_restore 命令 按步骤走 su postgres                   ...

  5. Auto Updating the exe from a network location when application starts z

    http://www.codeproject.com/Tips/869588/Auto-Updating-the-exe-from-a-network-location-when?msg=499218 ...

  6. 安装Sikulix

    1.sikulix可以在xp,win7,8,10 Mac 10.10.x 以及Linux/Unix 系统上安装 2.安装Java支持 3.下载sikulisetup1.1.0.jar(那里下前篇有介绍 ...

  7. 关于python中字典的一些总结

    1. 获取字典中的值,但是无异常 当在字典中取值的时候,可以使用如下两种方式: >>> d = {'name':'kel'} >>> d {'name': 'kel ...

  8. ansible安装及问题解决

    本文主要用来安装ansible,在进行安装的时候,也可以使用其他的版本进行安装,本文主要讲述安装ansible的步骤,还有常用问题的解决. 1.查看python版本 由此可以看到python的版本为2 ...

  9. ASP.NET MVC Razor视图引擎攻略

    --引子 看下面一段MVC 2.0的代码. <%if (Model != null){%> <p><%=Model%></p><%}%>&l ...

  10. HTML5新增属性

    [sourcecode language="plain"] <!DOCTYPE html> <html manifest="cache.manifest ...