数论——算数基本定理 - HDU 4497 GCD and LCM
GCD and LCM
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 3379 Accepted Submission(s): 1482
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.
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.
6 72
7 33
0
gcd(x,y,z) == G, lcm(x,y,z) == L
x' = x /G,y' = y /G ,z' = z / G; gcd( x', y',z') == 1,lcm(x',y',z') == L/G
这样的话对t = L/G 这个数进行素因子分解,t = p1^t1 * p2^t2 * p3^t3 ..... * pn ^tn;
满足上面条件的x,y,z一定为这样的形式。
x' = p1^i1 * p2^i2 *```* pn^in.
y' = p1^j1 * p2^j2 * ```*pn^jn.
z' = p1^k1 * p2^k2 * ```*pn^kn.
为了满足上面的条件,对于p1,一定有max(i1,j1,k1) = t1和min(i1,j1,k1) =0;
因为gcd(p1^i1,p1^j1,p1^k1)== 1 → min(i1,j1,k1) == 0;lcm(p1^i1,p1^j1,p1^k1) == p1^t1 => max(i1,j1,k1) == t1;
所以我们现在要做的是把L/G分解成n个素因数相乘,比如:28=2*2*7=2^2 * 7
对于每一个p来说,三个数的集合一定是{ 0, t, x | 0≤x≤t }
- x = 0 或 x = t:这种情况有
= 6 种 - 0 < x < t:这种情况x的取值可以为 0~t 的整数,一共有 t-1 个,而每一个数,都可以有
种排列方法,就是6*(t-1)
所以对每一个P来说,最后一共有 6*t 种取法 。
举个例子:252=2*2*7=2^2 * 3^3 * 7 一共有6*2+6*3+6=36种不同的(x,y,z)序列。
而如果L%G!=0,自然就没有解
#include <iostream>
using namespace std;
int f1(int n) {
, i = ;
) {
;
){
) {
t++;
n /= i;
}
res *= * t;
}
i++;
}
return res;
}
int main() {
int T;
cin >> T;
while (T--) {
int G, L;
cin >> G >> L;
)
cout << << endl;
else
cout << f1(L / G) << endl;
}
;
}
数论——算数基本定理 - HDU 4497 GCD and LCM的更多相关文章
- 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: 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 (非原创)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- 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 * ...
- 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(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)
质分解 + 简单计数.当时去比赛的时候太年轻了...这道题都没敢想.现在回过头来做了一下,发现挺简单的,当时没做这道题真是挺遗憾的.这道题就是把lcm / gcd 质分解,统计每个质因子的个数,然后 ...
- HDU 4497 GCD and LCM (分解质因数)
链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4497 假设G不是L的约数 就不可能找到三个数. L的全部素因子一定包括G的全部素因子 而且次方数 ...
- HDU 4497 GCD and LCM 素因子分解+ gcd 和 lcm
题意: 给两个数,lll 和 ggg,为x , y , z,的最小公倍数和最大公约数,求出x , y , z 的值有多少种可能性 思路: 将x , y , z进行素因子分解 素因子的幂次 x a1 a ...
随机推荐
- IIS利用X-Forwarded-For获得来访者的真实IP
https://help.aliyun.com/knowledge_detail/37948.html
- 【转载】SQL Server 2012将数据导出为脚本详细图解
前记: 从SQL SERVER 2008开始,我们就可以很方便的导出数据脚本,而无需再借助存储过程,但是SQL Server 2012和SQL Server 2008的导出脚本的过程还有一点细微的差别 ...
- Cookie,Sesstion,Application 缓存。
Cookie客户端缓存. 1.引言 随着浏览器的处理能力不断增强,越来越多的网站开始考虑将数据存储在「客户端」,那么久不得不谈本地存储了. 本地存储的好处: 一是避免取回数据前页面一片空白,如果不需要 ...
- layui登录后token问题
layui是一个非常简单且实用的后台管理系统搭建框架,里面的插件丰富使用简单,只需要在原有基础上进行修改即可,但是在数据处理方面略显薄弱,内置的jquery在实际过程中略显不足,若是能添加内置的mvc ...
- 设计模式入门,适配器模式,c++代码实现
// test07.cpp : Defines the entry point for the console application.// #include "stdafx.h" ...
- oauth2.0授权协议
参考文章 一.OAuth是什么? OAuth的英文全称是Open Authorization,它是一种开放授权协议.OAuth目前共有2个版本,2007年12月的1.0版(之后有一个修正版1.0a)和 ...
- CakePHP调用model类和foreach循环
1. 引入Model类 2.调用model类(Guarantee)下的getCity()方法 3.写sql语句 并返回获得值 4.foreach循环取得的城市
- <meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">的作用
本人对该标签理解不深,这里是复制了穆乙的文章:如果有人进来看到这篇文章,请按此https://www.cnblogs.com/pigtail/archive/2013/03/15/2961631.ht ...
- POJ P1741 Tree 解题报告
Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Def ...
- UC 优视发布“UC+”开放平台
7月5日消息,以浏览器起家的UC优视今天在2013移动互联网创新大会上正式发布“UC+”开放平台战略. UC优视公司总裁何小鹏同时表示:通过“UC+”开放平台,UC将UC浏览器全球四亿用户与移动端巨大 ...