hdu4497 GCD and LCM ——素数分解+计数
link:http://acm.hdu.edu.cn/showproblem.php?pid=4497
如果G%L != 0,说明一定无解。
把K = G / L质数分解,G / L = p1^t1 * p2^t2 * p3^t3 * ……;同时 x/= L, y/= L, z/=L,不影响结果。
假设三个数字的质数分解是:
x = p1^i1 * p2^i2 * p3^i3 * ……
y = p1^j1 * p2^j2 * p3^j3 * ……
z = p1^k1 * p2^k2 * p3^k3 * ……
要保证x, y, z互质,并且lcm(x, y, z) = K, 那么对于p1来说,i1, j1, k1里面一定有一个是0,并且一定有一个是t1,所以有3种情况:
0 0 t1 有3种
t1 t1 0 有3种
t1 0 1~t1-1 有(t1-1)*6种
一共是6*t1种。
根据乘法原理,总的种数是:6*t1 + 6*t2 + ……
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <algorithm> #include <queue> #include <deque> #include <queue> #include <list> #include <map> #include <set> #include <vector> #include <utility> #include <functional> #include <fstream> #include <iomanip> #include <sstream> #include <numeric> #include <cassert> #include <ctime> #include <iterator> const int INF = 0x3f3f3f3f; ][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}}; using namespace std; #define LL __int64 ; int prime[MAX]; bool flag[MAX]; int main(void) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin ); #endif // ONLINE_JUDGE int t; scanf("%d", &t); memset(flag, true, sizeof(flag)); ; ; i * i <= ; ++i) { if (flag[i]) ; j <= ; j+=i) flag[j] = false; } ; i <= ; ++i) if(flag[i]) prime[cnt++] = i; while (t--) { int G, L; scanf("%d%d", &G, &L); ; if (L % G) { printf("0\n"); continue; } int K = L / G, S = K; ; i < cnt; ++i) { if (prime[i] * prime[i] > S) break; ) { ; ) { K /= prime[i]; touch++; } ans *= touch * ; } } ) ans *= ; printf("%d\n", ans); } ; }
当你不明白一个东西的时候,就他妈的别用。
比如,ios::sync_with_stdio(false); 这货表示消除cin, cout 的输入输出缓存,如果混合使用cout, printf的时候,同时用cout的时候也用了endl(表示清空缓存),注意,在程序开头,已经打开消除cin, cout 的输入输出缓存这个开关了,这里又清空缓存,不是矛盾嘛!有意思的是,如果用c++交就会AC,用G++交就会WA,本来我想要输入输出快一点,结果弄巧成拙了。
还有一定要想清楚为什么要有71行。
参考:
https://www.byvoid.com/blog/fast-readfile/
http://www.cnblogs.com/cszero/archive/2012/02/11/Zero0ne.html
以后多注意这些东西。
嗨,中村。
hdu4497 GCD and LCM ——素数分解+计数的更多相关文章
- HDU4497 GCD and LCM(数论,质因子分解)
HDU4497 GCD and LCM 如果 \(G \% L != 0\) ,那么输出 \(0\) . 否则我们有 \(L/G=(p_1^{r_1})\cdot(p_2^{r_2})\cdot(p_ ...
- HDU4497——GCD and LCM
这个题目挺不错的,看到是通化邀请赛的题目,是一个很综合的数论题目. 是这样的,给你三个数的GCD和LCM,现在要你求出这三个数有多少种可能的情况. 对于是否存在这个问题,直接看 LCM%GCD是否为0 ...
- hdu4497 GCD and LCM
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total S ...
- 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_3071 Gcd & Lcm game 【素数分解 + 线段树 + 状压】
一.题目 Gcd & Lcm game 二.分析 非常好的一题. 首先考虑比较暴力的做法,肯定要按区间进行处理,对于$lcm$和$gcd$可以用标准的公式进行求,但是求$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_4497GCD and LCM(合数分解)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Other ...
- HDU 4497 GCD and LCM(数论+容斥原理)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
随机推荐
- U9单据UI开发--单据类型UI开发
1.在解决方案下新建UI界面项目,命名以UI作为后缀 2.先删除系统默认新建的UI界面数据模型,并新建界面数据 3.新建单据类型UIModel(界面数据),以model作为界面数据后缀名 4.修改单据 ...
- Shiro Security
手动创建shiro Filter的java代码 // Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecu ...
- 探究chrome下的开发工具的各功能
F12 一.网页寻找js事件的位置,或者某一个次究竟在哪个相关的文件中可以全局搜索: ①控制台右上角的:(Customize and control DevTools)三个点点开,---->Se ...
- 学习mongo系列(八)密码与权限
一.设置密码及用户角色[1] > db.createUser(... {... user: "maxh",... pwd: "123",... roles ...
- Spring事务管理只对出现运行期异常进行回滚
原文:http://blog.csdn.net/abc19900828/article/details/39497631 使用spring难免要用到spring的事务管理,要用事务管理又会很自然的选择 ...
- Sealed密封类
using System; using System.Collections.Generic; using System.Linq; using System.Text; #region 概述 //在 ...
- 简单回忆一下JavaScript中的数据类型
说到JavaScript,大家都应该知道,它是一门脚本语言,也是一门弱类型语言,也是一门解析型的语言,同时也是一门动态类型的语言. 很好,至于JavaScript中数据类型.其分为基本数据类型和复杂数 ...
- CSS样式汇总
1. Overflow: 是否隐藏超出容器范围之外的内容,主要参数包括Hidden(隐藏),Auto(根据容器内容自动显示滚动条),scroll(显示滚动条,即使内容不超出容器范围,也会显示一个边框, ...
- iOS中JS 与OC的交互(JavaScriptCore.framework)
iOS中实现js与oc的交互,目前网上也有不少流行的开源解决方案: 如:react native 当然一些轻量级的任务使用系统提供的UIWebView 以及JavaScriptCore.framewo ...
- Ubuntu 16.04服务器安装及软件配置
1.配置静态地址 vim /etc/network/interfaces auto enp1s0 iface enp1s0 inet static address 192.168.1.131 netm ...