题意:三个数x, y, z. 给出最大公倍数g和最小公约数l.求满足条件的x,y,z有多少组.

题解:设n=g/l n=p1^n1*p2^n2...pn^nk (分解质因数

  那么x = p1^x1 * p2^x2 * .... ^ pn^xk

    y = p1^y1 * p2^y2 * .... ^ pn^yk

    x = p1^z1 * p2^z2 * .... ^ pn^zk

那么对于任意i (0<=i<=k) 都有 min(xi, yi, zi) = 0, max(xi, yi, zi) = ni

于是枚举每一个质因数的分配情况即可得出答案.

对于每一个i pi ni

有一个因子要为pi^ni 有一个因子要为pi^0

于是一共有(ni+1)^3(所有情况) - ni^3(没有0) - ni^3(没有ni) + (ni-1)^3(既没有0也没有ni) 中情况

枚举出所有小于根号n 的因数 如果 没有除尽 剩下的是一个大的质因数

感悟:

应该算是比较水的题

但是由于很少做数论的题

所以总会觉得是因为有什么定理不会 所以不愿意去思考

也无从下手

以后碰到lcm和gcd的题 知道了有一个角度是分解质因数

#include <bits/stdc++.h>
using namespace std; int main()
{
freopen("in", "r", stdin);
int T;
cin >> T;
while (T--) {
int g, l;
cin >> g >> l;
if (l % g) {
printf("0\n");
continue;
}
int n = l / g;
int limit = (int) sqrt((double)n);
int cnt, ans = ;
for (int i = ; i <= limit; ++i) {
if (n % i == ) {
cnt = ;
while (n % i == ) {
n /= i;
cnt++;
}
ans *= cnt * ;
}
}
if (n > ) ans *= ;
printf("%d\n", ans);
}
return ;
}

  

HDU 4497 GCD and LCM (数论)的更多相关文章

  1. HDU 4497 GCD and LCM(数论+容斥原理)

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

  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 数学

    GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...

  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(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

  7. hdu 4497 GCD and LCM(2013 ACM-ICPC吉林通化全国邀请赛——题目重现)

    质分解 + 简单计数.当时去比赛的时候太年轻了...这道题都没敢想.现在回过头来做了一下,发现挺简单的,当时没做这道题真是挺遗憾的.这道题就是把lcm  / gcd 质分解,统计每个质因子的个数,然后 ...

  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 素因子分解+ gcd 和 lcm

    题意: 给两个数,lll 和 ggg,为x , y , z,的最小公倍数和最大公约数,求出x , y , z 的值有多少种可能性 思路: 将x , y , z进行素因子分解 素因子的幂次 x a1 a ...

随机推荐

  1. POJ3034+DP

    题意:给定一个N*N的矩阵, 然后在这个矩阵的每个格子在任意时间会出现一个鼹鼠,这个出现     出现鼹鼠的时间是输出信息所确定的. 现在你手里有一把锤子能够去锤这些鼹鼠. 你能     够移动锤子, ...

  2. hdu 4658 Integer Partition

    五角数定理!!可以参考这个http://www.cnblogs.com/xin-hua/p/3242428.html  代码如下: #include<iostream> #include& ...

  3. struts2文件下载 火狐浏览器的文件名乱码问题

    这是一个文件下载的action,红色部分为火狐浏览器需要特地做的事情. @Controller @Scope(value = "prototype") public class F ...

  4. hibernate annotation注解 columnDefinition用法

    column注解中的columnDefinition属性用于覆盖数据库DDL中的语句:(MySql) @Column(columnDefinition = "int(11) DEFAULT ...

  5. IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set

    在file-setting里面,找到maven的设置: 先加入一个环境变量 然后配置一个JVM的参数: -Dmaven.multiModuleProjectDirectory=$M2_HOME OK ...

  6. Fibonacci sequence 求余数

    #include <iostream> using namespace std; int f(int n); int main() { int n; cin>>n; doubl ...

  7. 网上图书商城项目学习笔记-037工具类之BaseServlet及统一中文编码

    1.统一中文编码分析 tomcat默认esetISO-8859-1编码,在servlet中,可能通过request的setCharacterEncoding(charset)和response.set ...

  8. Spring的依赖注入

    依赖注入—手工装配(XML方式)--通过属性注入(相应属性必须有setter方法才行,同时,要有无参构造方法): <!-- 通过属性注入(setter方法) --> <bean id ...

  9. 理解TCP/IP协议

    TCP/IP协议是Transmission Control Protocol/Internet Protocol的简写,中译名为传输控制协议/因特网互联协议. 单从TCP/IP协议这个名称看,好多人误 ...

  10. 捉虫记2:windows程序句柄泄露的上下文环境

    作为程序员,开发程序是基本功,而调试程序也是必不可少的技能之一.软件在主体功能开发完成后会经历各个阶段的测试,才会被发布.在测试过程中,出现较多的可能就是内存泄漏,句柄泄漏,异常崩溃等属于非功能型的软 ...