题意:求有多少对数对(i,j)满足lcm(i,j) = n,1<=i<=j, 1<=n<=1e14。

分析:根据整数的唯一分解定理,n可以分解为(p1^e1)*(p2^e2)*(p3^e3)*...*(pn^en)。其中pi是每个不同的素因子。

同样可将 i 和 j 分解为(a1^c1)*(a2^c2)^(a3^c3)...(an^cn) 和 (b1^d1)*(b2^d2)*(b3^d3)*...(bn^dn)。

因为lcm(i,j) = n。所以对任意 i,都有max(ci,di)= ei ,0 <= min(ci,di) <= ei,所以对n的每个素因子,都有2*(ei+1)-1种情况(减1是因为ci=di=ei的情况被算了2次)。

所有的可能 t 就是 (2ei+1)之积。这是有序对的数量,求无序对的时候 将 (t+1)/2,加1是因为(n,n)的情况本身只有一种可能。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn =1e7+;
const int INF =0x3f3f3f3f; bool notprime[maxn<<];
vector<int> prime;
//prime[0] 表示当前范围内有多少素数,prime[i] 表示第i个素数是多少
void pre()
{
memset(notprime,,sizeof(notprime));
notprime[] = notprime[] = true;
for(int i=;i<maxn;++i){
if(!notprime[i]) prime.push_back(i);
for(int j= ; j<prime.size() && prime[j] <= maxn / i ;++j){
notprime[prime[j]*i] = true;
if(i%prime[j]==) break;
}
}
} LL getFactor(LL n)
{
LL tmp = n , res=;
for(int i=;i<prime.size() && prime[i]*prime[i]<=tmp;++i){
int cnt =;
while(tmp%prime[i]==){
cnt++;
tmp/=prime[i];
}
res *=(*cnt + );
}
if(tmp>) res*= ;
res++;
res>>=;
return res;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
pre();
int T,N,u,v,tmp,cas=;
scanf("%d",&T);
while(T--){
LL n; scanf("%lld",&n);
LL res= getFactor(n);
printf("Case %d: %lld\n",cas++,res);
}
return ;
}

LightOJ - 1236 (唯一分解定理)的更多相关文章

  1. LightOJ - 1341唯一分解定理

    唯一分解定理 先分解面积,然后除2,再减去面积%长度==0的情况,注意毯子不能是正方形 #include<map> #include<set> #include<cmat ...

  2. Aladdin and the Flying Carpet LightOJ 1341 唯一分解定理

    题意:给出a,b,问有多少种长方形满足面积为a,最短边>=b? 首先简单讲一下唯一分解定理. 唯一分解定理:任何一个自然数N,都可以满足:,pi是质数. 且N的正因子个数为(1+a1)*(1+a ...

  3. LightOJ 1341 唯一分解定理

    Aladdin and the Flying Carpet Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld &a ...

  4. lightoj 1220 唯一分解定理

    #include<bits/stdc++.h> using namespace std; #define maxn 1000005 #define ll long long int v[m ...

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

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

  6. lightoj 1236 正整数唯一分解定理

    A - (例题)整数分解 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     6 ...

  7. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  8. LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...

  9. LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria

    题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...

随机推荐

  1. PAT002 Reversing Linked List

    题目: Given a constant K and a singly linked list L, you are supposed to reverse the links of every K ...

  2. ORB特征提取与匹配

    ORB特征是目前最优秀的特征提取与匹配算法之一,下面具体讲解一下: 特征点的检测 图像的特征点可以简单的理解为图像中比较显著显著的点,如轮廓点,较暗区域中的亮点,较亮区域中的暗点等.ORB采用FAST ...

  3. servlet各版本区别以及dynamic web module 版本之间的区别

    java的web系统有多种类型,比如静态的和动态的,然后动态的java web project要设置dynamic web module,也就是动态网页模型,他必须要喝对应的服务器搭配好了才能跑,今天 ...

  4. Wex5循环某个div节点下的所有img标签,替换其src属性值

    Model.prototype.newsDetailAfterRefresh = function(event){ var newsDiv = this.getElementByXid("n ...

  5. 怎么查看mac系统是32位还是64位的操作系统

    如何查看mac系统是32位还是64位的操作系统 (一)点击工具栏左上角点击 (苹果Logo)标志,关于本机  -->  更多信息 --> 系统报告  -->(左侧栏中)软件 (二) ...

  6. 3969 [Mz]平方和【斐波那契平方和】

    3969 [Mz]平方和  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 大师 Master 题解  查看运行结果     题目描述 Description 斐波那契数列:f[0 ...

  7. 【BZOJ4145】[AMPPZ2014]The Prices 状压DP

    [BZOJ4145][AMPPZ2014]The Prices Description 你要购买m种物品各一件,一共有n家商店,你到第i家商店的路费为d[i],在第i家商店购买第j种物品的费用为c[i ...

  8. 【BZOJ4870】[Shoi2017]组合数问题 动态规划(矩阵乘法)

    [BZOJ4870][Shoi2017]组合数问题 Description Input 第一行有四个整数 n, p, k, r,所有整数含义见问题描述. 1 ≤ n ≤ 10^9, 0 ≤ r < ...

  9. [LintCode] 二叉树的后序遍历

    The recursive solution is trivial and I omit it here. Iterative Solution using Stack (O(n) time and  ...

  10. cookie的简单留言框

    我们在网页浏览时退出后,再次进入时会有上次的记录,这就用的上cookie属性了,cookie就是服务器暂存放在你计算机上的一笔资料,好让服务器用来辨认你的计算机.当你在浏览网站的时候,Web服务器会先 ...