题意:求有多少对数对(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. import _mysql----ImportError: DLL load failed: %1 不是有效的 Win32 应用程序。

    背景:安装了mysql,练习sql 操作,提示 ImportError DLL load failed: %1 不是有效的 Win32 应用程序 解决方法: 操作系统win10,64位,查看安装的my ...

  2. AWT从概念产生到完成实现只用了一个月

    这种糟糕的设计选择使得那些拥护Java“一次编写,到处运行 (write once, run anywhere)”信条的程序员们过得并不舒畅,因为AWT并不能保证他们的应用在各种平台上表现得有多相似. ...

  3. Torch-RNN运行过程中的坑 [2](Lua的string sub函数,读取中文失败,乱码?)

    0.踩坑背景 仍然是torch-rnn/LanguageModel.lua文件中的一些问题,仍然是这个狗血的LM:encode_string函数: function LM:encode_string( ...

  4. 【R】自定义描述统计函数-从均值到峰度偏度

    data_show<-function(x) { n<-length(x) m<-mean(x) v<-var(x) s<-sd(x) me<-median(x) ...

  5. 微软官方SqlHelper类 数据库辅助操作类

    数据库操作类真的没有必要自己去写,因为成熟的类库真的非常完善了,拿来直接用就好,省时省力. 本文就为大家介绍微软官方的程序PetShop4.0中的SqlHelper类,先来做一下简单的介绍,PetSh ...

  6. javascript 字符串进行 utf8 编码的方法(转)

    实践中碰到了一个大问题,在 javascript 中,可能有一些中文字符串,我们想将其进行二进制流编码的时候,需要将其转换为 utf8 的编码. 也就是说,输入的是一个字符串:'呆滞的慢板今天挣了10 ...

  7. BZOJ 3261 最大异或和 可持久化Trie树

    题目大意:给定一个序列,提供下列操作: 1.在数组结尾插入一个数 2.给定l,r,x,求一个l<=p<=r,使x^a[p]^a[p+1]^...^a[n]最大 首先我们能够维护前缀和 然后 ...

  8. 推荐一个CSS类库

    animate.css 一个封装好的动画效果类

  9. 160801、BlockingQueue处理多线程

    前面介绍过spring的taskExecutor,今天介绍一个jdk里处理多线程的方法 一.spring的配置文件(注入bean) <bean id="cmsClickButtonMn ...

  10. 转义字符的理解(JAVA、字符串和正则表达式)

    一.原理总结: 要理解转义,首先要从正则表达式说起. 在正则表达式中:*和\是特殊字符:为了匹配这两个字符本身,正则表达式中需要写为\*和\\ 在Java中,只能用字符串表示正则表达式,所以需要把\* ...