HDU 4497 GCD and LCM (数学,质数分解)
题意:给定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 (数学,质数分解)的更多相关文章
- 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 ...
- 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 质因素分解+排列组合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: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- 数论——算数基本定理 - 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 (非原创)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- 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,求满 ...
- HDU 4497 GCD and LCM (分解质因数)
链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4497 假设G不是L的约数 就不可能找到三个数. L的全部素因子一定包括G的全部素因子 而且次方数 ...
- 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 * ...
随机推荐
- WEBUS2.0 In Action - 搜索操作指南 - (2)
上一篇:WEBUS2.0 In Action - 搜索操作指南(1) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(3) 2. 使用Query Query是所有查询的基类, 它一 ...
- (转)每天一个Linux命令(5): rm
http://www.cnblogs.com/peida/archive/2012/10/26/2740521.html 昨天学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和 ...
- 【英语】Bingo口语笔记(8) - 爆破音的发音技巧
轻读,有时候甚至是听不到的,就嘴巴碰一下而已.
- Java正则表达式之语法规则
正则表达式是一种强大而灵活的文本处理工具,使用正则表达式能够以编程的方式,构造复杂的文本模式,并对输入的字符串进行搜索.一旦找到了匹配这些模式的部分,就能够随心所欲地它们进行处理.正则表达式提供了一种 ...
- 查看Linux下端口占用情况的命令
在使用Linux系统的过程中,有时候会遇到端口被占用而导致服务无法启动的情况.比如HTTP使用80端口,但当启动Apache时,却发现此端口正在使用. 这种情况大多数是由于软件冲突.或者默认端口设置不 ...
- Java中SynchronizedMap与ConcurrentHashMap的对比
如何使用 概述 ConcurrentHashMap: 线程安全: 其将整个Hash桶进行了分段segment,也就是将这个大的数组分成了几个小的片段segment,而且每个小的片段segment上面都 ...
- Fidder 监控WCF
Client端配置 <?xml version="1.0" encoding="utf-8" ?> <configuration> &l ...
- 删除binlog的方法
不知道你有没有为mysql的binlog占用大量磁盘感到无奈,my.cnf里binlog的size可以设置多大做分割,但没有看到删除的配置,在mysql里show了一下variables, mysql ...
- Linux 客户端 下乱码的解决方法
最近使用xshell登陆英文版redhat,由于某些文件是中文编码,在xshell下显示乱码.折腾了很久终于找到了解决的方法,希望可以对大家有用.其他语言乱码的话,解决方法和此类似! 首先检查系统的l ...
- eclipse插件explorer安装使用
我们知道myeclipse有个open in explorer的按钮.可以方便我们打开任意IDC下的文件或则插件目录 但是eclipse下确没有.因此需要下载下载个eclipse explorer插件 ...