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 * ...
随机推荐
- 字符集设置为UTF-8
vi /etc/my.cnf [mysqld] character-set-server=utf8 [mysql] default-character-set=utf8 来自为知笔记(Wiz)
- BZOJ 3631 松鼠的新家
链剖. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- 【JavaScript学习笔记】画图
<!DOCTYPE HTML> <html> <head> <script type="text/javascript"> var ...
- 使用过的Linux命令
1 在vim中编辑python,由于tab是8个空格,然而python中是4个,需要替换 :%s/\t/ /g 2 tar tar -czvf topic_dt_poi.0801.0818.ta ...
- Linux Shell编程(5):整数运算
http://blog.sina.com.cn/s/blog_6db275da0101asmf.html #!/bin/sh let a=$1+$2 b=$[$1+$2] ((c=$1+$2)) d= ...
- 计算机网络——超文本传送协议HTTP
一.简述 每个万维网网点都有一个服务器进程,它不断地监听TCP的端口80,以便发现是否有浏览器向它发出连接建立请求.一旦监听到连接建立请求并建立了TCP连接之后,浏览器就向万维网服务器发出浏览某个页面 ...
- OpenGL学习之路(二)
1 引子 在上一篇读书笔记中,我们对书本中给出的例子进行详细的分析.首先是搭出一个框架:然后填充初始化函数,在初始化函数中向OpenGL提供顶点信息(缓冲区对象)和顶点属性信息(顶点数组对象),并启用 ...
- 自定义View--一个简单地圆形Progress效果
先看效果图吧 我们要实现一个自定义的再一个圆形中绘制一个弧形的自定义View,思路是这样的: 先要创建一个类ProgressView,继承自View类,然后重写其中的两个构造方法,一个是一个参数的,一 ...
- 18、GPS技术
GPS核心API Android SDK为GPS提供了很多API,其中LocationManager类是这些API的核心.LocationManager是一个系统服务类,与TelephonyManag ...
- Java并发编程-synchronized
多线程的同步机制对资源进行加锁,使得在同一个时间,只有一个线程可以进行操作,同步用以解决多个线程同时访问时可能出现的问题.同步机制可以使用synchronized关键字实现.synchronized关 ...