LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236
题意:给你一个数n,求有多少对(i, j)满足 LCM(i, j) = n, (i<=j), n <= 1e14;
之前做的那道LightOj 1215 中有说过:LCM(x, y) = ∏(所有质因子幂高的项之积);
那么本题就先把n分解质因子幂的形式,即 n = p1a1*p2a2*...*pkak;(pi为质数)
现在先不管i和j的大小,当 i 中包含因子p1a1时,j中可以包含p10|1|2|...|a1共有(a1+1)种可能,同样当j也有这种可能,所以共有2*(a1+1)
要减去 i 和 j 相等等于a1的时候;所以共有2*a1+1种,对于每个因子,都有这样的,所以连乘起来即可,除了i=j的情况每种情况都有两次,所以要/2+1;
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long LL;
const int oo = 0xfffffff;
const int N = 1e7+;
const double eps = 1e-; bool f[N];///用int会MLE;
int p[N/], k = ; void Prime()
{
for(int i=; i<N; i++)
{
if(!f[i]) p[k++] = i;
for(int j=i; j<N; j+=i)
f[j] = true;
}
} int main()
{
Prime();
///printf("%d\n", k); int T, t = ; scanf("%d", &T); while(T--)
{
LL n; scanf("%lld", &n); LL ans = ; for(int i=; i<k&&(LL)p[i]*p[i]<=n; i++)
{
LL cnt = ;
while(n%p[i] == )
{
cnt ++;
n /= p[i];
}
if(!cnt) continue;
ans *= *cnt+;
} if(n > ) ans *= ; ans = ans/ + ; printf("Case %d: %lld\n", t++, ans);
}
return ;
}
LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )的更多相关文章
- LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS Memor ...
- LightOJ 1236 - Pairs Forming LCM(素因子分解)
B - Pairs Forming LCM Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOJ - 1236 - Pairs Forming LCM(唯一分解定理)
链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...
- LightOJ 1236 Pairs Forming LCM【整数分解】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1236 题意: 找与n公倍数为n的个数. 分析: ...
- LightOJ 1236 Pairs Forming LCM 合数分解
题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...
- LightOj 1236 Pairs Forming LCM (素数筛选&&唯一分解定理)
题目大意: 有一个数n,满足lcm(i,j)==n并且i<=j时,(i,j)有多少种情况? 解题思路: n可以表示为:n=p1^x1*p2^x1.....pk^xk. 假设lcm(a,b) == ...
- 1236 - Pairs Forming LCM
1236 - Pairs Forming LCM Find the result of the following code: long long pairsFormLCM( int n ) { ...
- Light oj 1236 - Pairs Forming LCM (约数的状压思想)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...
- 1236 - Pairs Forming LCM -- LightOj1236 (LCM)
http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...
随机推荐
- Cache的使用
公共方法Add 将指定项添加到 Cache 对象,该对象具有依赖项.过期和优先级策略以及一个委托(可用于在从 Cache 移除插入项时通知应用程序). Equals(从 Object 继承) 已重载. ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 A. Anagrams
A. Anagrams time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- ccc tiledmap 获取元素属性
cc.Class({ extends: cc.Component, properties: { elementLable: { default: null, type : cc.Label }, ma ...
- gulp顺序执行任务
gulp的任务的执行是异步的. 所以,当我写完一系列的任务,准备一股脑地执行. # gulp.task('prod', ['clean', 'compass', 'image', 'style', ' ...
- overflow-y:auto
overflow-x:auto; overflow-y:auto; X轴和Y轴自适应:
- 20161005 NOIP 模拟赛 T3 解题报告
subset 3.1 题目描述 一开始你有一个空集,集合可以出现重复元素,然后有 Q 个操作 1. add s 在集合中加入数字 s. 2. del s 在集合中删除数字 s.保证 s 存在 3. c ...
- 【BZOJ】3757: 苹果树
http://www.lydsy.com/JudgeOnline/problem.php?id=3757 题意:n个节点的树,每个点有一种颜色.现有m种询问,每次询问x y a b表示x到y的路径上颜 ...
- Ninject使用demo
public class HomeController : Controller { public ActionResult Index() { //核心对象 IKernel ninjectKerne ...
- hadoop CLASSNAME命令使用注意点
Hadoop中可是使用hadoop CLASSNAME命令.这个CLASSNAME就是你写好的类名.hadoop CLASSNAME命令类似于java classname. 使用hadoop CLAS ...
- uva 1382 - Distant Galaxy
题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=91208#problem/G 题意: 给出平面上的n个点,找出一个矩形,使得边 ...