LightOJ 1236 Pairs Forming LCM 合数分解
题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数
分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^13个因子 即8000多因子
所以每次可以递归暴力寻找一个因子,然后选好了以后,看唯一分解不同种素数还有哪种没有用,符合条件的只能用这些没有用过的,然后直接统计
注:由于最终每个对都被统计了两次,所以/2,由于本身也算一对,所以+1
代码:
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e7+;
const int INF=0x3f3f3f3f;
int cnt;
bool v[N];
LL prime[];
void getprime(){
for(int i=;i*i<=N-;++i)
if(!v[i])
for(int j=i*i;j<=N-;j+=i)
v[j]=;
for(int i=;i<=N-;++i)
if(!v[i])prime[++cnt]=i;
}
int ans;
vector<LL>g,c;
bool vis[];
void dfs(int pos,LL res){
if(pos==g.size()){
int tmp=;
for(int i=;i<g.size();++i){
if(vis[i])continue;
tmp*=(c[i]+);
}
ans+=tmp;
return;
}
dfs(pos+,res);
vis[pos]=;
for(LL i=,k=g[pos];i<=c[pos];++i,k*=g[pos])
dfs(pos+,res*k);
vis[pos]=;
return;
}
int main()
{
getprime();
int cas=,T;
scanf("%d",&T);
while(T--){
LL t,n;
scanf("%lld",&n),t=n;
g.clear(),c.clear();
for(int i=;i<=cnt&&prime[i]*prime[i]<=t;++i){
if(t%prime[i])continue;
int tot=;
g.push_back(prime[i]);
while(t%prime[i]==)t/=prime[i],++tot;
c.push_back(tot);
}
if(t>)g.push_back(t),c.push_back();
ans=;
dfs(,);
printf("Case %d: %d\n",++cas,(ans>>)+);
}
return ;
}
LightOJ 1236 Pairs Forming 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 (分解素因子,LCM )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i, j)满足 LCM(i, j) = n, ...
- LightOJ 1236 Pairs Forming LCM【整数分解】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1236 题意: 找与n公倍数为n的个数. 分析: ...
- 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 (素数筛选&&唯一分解定理)
题目大意: 有一个数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<= ...
随机推荐
- 要做一款APP-解放双手
对方打字或发语音,我可以选择看屏幕或者听. 我说话,能够转化为文字.不需要点击开始按钮的那种.
- OpenDialog获取文件名
//OpenDialog获取文件 procedure TForm2.Button1Click(Sender: TObject); begin File_Path:=''; if OpenDialog1 ...
- TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error
新建的数据库,在配置完listener的时候报这个错. 参考文章:https://community.oracle.com/message/4098938 http://blog.csdn.net/l ...
- C++ 实现设计模式之观察者模式
1. 什么是观察者模式? 观察者模式(有时又被称为发布-订阅Subscribe>模式.模型-视图View>模式.源-收听者Listener>模式或从属者模式)是软件设计模式的一种.在 ...
- WebService 学习总结
一.概念 Web Web应用程序 Web服务( Web Serivce), SOAP, WSDL, UDDI .Net 框架 ASP.net IIS C#, 代理(委托) 二.实践 1.创建WebSe ...
- python 中参数*args, **kwargs
def func(*args, **kwargs): print 'args : ', args print 'kwargs :', kwargs def test(): func(1,2,'x',' ...
- Hadoop集群系类文章
http://www.cnblogs.com/xia520pi/archive/2012/04/08/2437875.html 后续文章地址:http://www.xiapistudio.com/ta ...
- BZOJ 3955 Surely You Congest 解题报告
首先,我们可以求出源为 $1$ 号点的最短路图以及各个点到 $1$ 号点的最短路. 然后我们考虑那些距离不同的点,是一定不会发生拥堵现象的. 然后我们就只需要考虑那些距离相同的点,就相当于做一个最大流 ...
- Nginx完整配置说明
http://blog.csdn.net/marising/article/details/3979493 可以参考如下的完整例子 http://wiki.codemongers.com/NginxF ...
- HDU 5015 233 Matrix
题意:给定一个矩阵的第0列的第1到n个数,第一行第1个数开始每个数分别为233, 2333........,求第n行的第m个数. 分析: 其实也没那么难,自己想了半天还没往对的方向想,m最大1e9,应 ...