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 ...
随机推荐
- 使用hue+oozi构建任务调度系统
oozie调度系统调研 1. 关于oozie的简单说明 oozie应用程序目录结构说明: 一个完整的oozie应用程序一般情况下至少包含三个文件及目录:job.properties.workflow. ...
- ubuntu 安装eclipse,adt,android sdk,离线
1.安装jdk 环境变量 $ sudo gedit ~/.bashrc export JAVA_HOME=/usr/local/jdk1.8.0_65export JRE_HOME=${JAVA_HO ...
- 【matlab】合并两个cell
a=cell(1,2);a{1}=zeros(1,2);a{2}=zeros(2,2); b=cell(1,2);b{1}=zeros(1,3);b{2}=zeros(1,3);aa=[a,b] ...
- oracle中如何创建dblink
当用户要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本地数据库一样访问远程数据库表中的数据.下面讲介绍如何在本地数 ...
- HTML 图像<img>
定义和用法: img元素向网页中嵌入一副图像. 请注意:从技术上讲,<img>标签并不会在网页中插入图像,而是从网页上链接图像.<img>标签创建的是被引用图像的占位空间. 属 ...
- python目前最好用的IDE——pycharm
PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元测试.版本控制. ...
- mysql 二进制日志
1.日志类型 二进制日志记录了所有对mysql数据库的修改事件,包括增删改事件和对表结构的修改事件. 2.配置使用二进制日志 在my.ini 配置 log-bin=mysql-bin ...
- Octopus系列之价格计算公式
百分比:在原价的基础上优惠5%,相当于95%折销售实际价格:最后实际销售的价格[基准价格:如果有特价就基于特价,没有特价基于原价]优惠金额:减少的金额 批量优惠 百分比: 原价*(1-5%)的算法实际 ...
- Yii2-redis
安装:composer require --prefer-dist yiisoft/yii2-redisredis 版本 >= 2.6.12 添加配置: 'components' => [ ...
- Appium移动自动化测试(一)--安装Appium
Appium 自动化测试是很早之前就想学习和研究的技术了,可是一直抽不出一块完整的时间来做这件事儿.现在终于有了. 反观各种互联网的招聘移动测试成了主流,如果再不去学习移动自动化测试技术将会被淘汰. ...