题目链接: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 )的更多相关文章

  1. LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memor ...

  2. LightOJ 1236 - Pairs Forming LCM(素因子分解)

    B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  3. LightOJ - 1236 - Pairs Forming LCM(唯一分解定理)

    链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...

  4. LightOJ 1236 Pairs Forming LCM【整数分解】

    题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1236 题意: 找与n公倍数为n的个数. 分析: ...

  5. LightOJ 1236 Pairs Forming LCM 合数分解

    题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...

  6. 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) == ...

  7. 1236 - Pairs Forming LCM

    1236 - Pairs Forming LCM   Find the result of the following code: long long pairsFormLCM( int n ) {  ...

  8. Light oj 1236 - Pairs Forming LCM (约数的状压思想)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...

  9. 1236 - Pairs Forming LCM -- LightOj1236 (LCM)

    http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...

随机推荐

  1. WPF:依赖属性的数据绑定

    One of the strengths of WPF is its data binding capabilities. Although data binding is not new (in f ...

  2. HDOJ-1002

    用java写大数,感觉就是BUG import java.math.*; import java.io.*; import java.util.*; public class Main{ public ...

  3. 163源报错Hash Sum mismatch 解决方法

    Ubuntu server 用的163的源,报错: W: Failed to fetch http://mirrors.163.com/ubuntu/dists/precise-updates/mai ...

  4. 在SUBLIME TEXT中安装SUBLIMELINTER进行JS&CSS代码校验

    一:Sublime Text 中需要先安装Package Control.(如果有则无需安装) 安装方法:打开Sublime Text控制台(快捷键Ctrl+`),在控制台粘贴以下代码,按回车执行. ...

  5. 提高安全性而在HTTP响应头中可以使用的各种响应头字段

    本文介绍在Web服务器做出响应时,为了提高安全性而在HTTP响应头中可以使用的各种响应头字段.由于部分浏览器中有可能对某些字段或选项不提供支持,所以在使用这些字段时请先确认客户端环境. X-Frame ...

  6. C++11 feature: move constructor

    There are heaps of good articles out there about C++ features including this move constructor. Howev ...

  7. Win10 利用安装盘启用 .NET Framework 3.5

    以管理员身份运行命令提示符,在“管理员:命令提示符”窗口中输入以下命令:dism.exe /online /enable-feature /featurename:netfx3 /Source:D:\ ...

  8. android 百度地图开发

    package sposition.webjoy.net.sendposition; import android.os.Bundle; import android.support.design.w ...

  9. html2canvas根据DOM元素样式实现网页截图

    html2canvas是一个相当不错的JavaScript类库,它使用了html5和css3的一些新功能特性,实现了在客户端对网页进行截图的功 能.html2canvas通过获取页面的DOM和元素的样 ...

  10. Maven构建简单的多模块项目

    复制于http://www.cnblogs.com/luxh/p/3506750.html 做个记录 一般web项目会进行分模块开发.这里简单分为domain(领域层).persist(持久层).se ...