题意:求有多少对数对(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. Transporting Data Between Database

    The Export utility can provide a logical backup of: Database objects A tablespace An entire database ...

  2. number(4,2)

     number(4,2)  ##.## 例如:45.23 number(6,2)就是####.##   例如:9994.11   4代表总共有效位数为4位2代表小数位为2位

  3. java简易excel导入导出工具(封装POI)

    Octopus 如何导入excel 如何导出excel github项目地址 Octopus Octopus 是一个简单的java excel导入导出工具. 如何导入excel 下面是一个excel文 ...

  4. 第一百四十八节,封装库--JavaScript,菜单切换

    第一百四十八节,封装库--JavaScript,菜单切换 首先在封装库封装点击切换方法 /** dian_ji_qie_huan()方法,设置点击切换,将元素设置成点击切换,也就是点击目标元素后,循环 ...

  5. 【BZOJ】1661: [Usaco2006 Nov]Big Square 巨大正方形(暴力)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1661 暴力大法好... 枚举对角线(注意,一种对角线2种情况就行了,自己想...) 然后可以算出其它 ...

  6. PHP 清除HTML代码、空格、回车换行符的函数

    function DeleteHtml($str) { $str = trim($str); $str = strip_tags($str,""); $str = ereg_rep ...

  7. ASP.NET中Dictionary基本用法实例分析

    本文实例讲述了ASP.NET中Dictionary基本用法.分享给大家供大家参考,具体如下: //Dictionary位于System.Collections.Generic命名空间之下 /*  * ...

  8. hdu 4568(SPFA预处理+TSP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4568 思路:先用spfa预处理出宝藏与宝藏之间的最短距离,宝藏到边界的最短距离,然后就是经典的求TSP ...

  9. HTTP请求的过程&HTTP/1.0和HTTP/1.1的区别&HTTP怎么处理长连接

    http://www.cnblogs.com/GumpYan/p/5821193.html

  10. GL 纹理 格式 资料备份

    分别转载至:http://www.tuicool.com/articles/qAbYfq    和 http://www.verydemo.com/demo_c161_i114362.html 在手机 ...