题意:求所有小于等于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 合数分解的更多相关文章

  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 (分解素因子,LCM )

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i,  j)满足 LCM(i, j) = n, ...

  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(唯一分解定理)

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

  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. C#对XML、JSON等格式的解析

    C#对XML.JSON等格式的解析 一.C#对XML格式数据的解析 1.用XMLDocument来解析 XmlDocument xmlDocument = new XmlDocument(); xml ...

  2. CSS3 基本知识

    1.CSS3 简介 CSS 指层叠样式表 (Cascading Style Sheets),用于控制网页的样式和布局,CSS3 是最新的 CSS 标准. 在网页制作时采用层叠样式表,可以有效的对页面的 ...

  3. 微信公众号-5秒内不回复测试并处理方案,顺便复习php 时间执行

    在index.php中 file_put_contents('has_request.txt','请求时间:'.date('YmdHis')."\n",FILE_APPEND); ...

  4. MySQL基础学习之索引

    创建新表新索引 CREATE TABLE 表名(数据名 类型,INDEX  索引名称(属性)) 创建存在表的索引 CREATE INDEX 索引名称  ON 表名(属性) 修改索引 ALTER TAB ...

  5. php实现单链表

    <?php /** * 单链表 */ class Demo { private $id; public $name; public $next; public function __constr ...

  6. SQL注入原理二

    随着B/S模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多. 但是由于程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候 ,没有对用户输入数据的合法性进行判断,使应用程序存 ...

  7. python27读书笔记0.1

    --Notes: 测试环境:Windows ,python 2.7.3,python 自带的IDLE #-*- coding: utf-8 -*- # First Lesson# --- Line s ...

  8. FolderBrowserDialog组件选择文件夹

    1.选择路径 this.folderBrowserDialog1.ShowDialog(); if (this.folderBrowserDialog1.ShowDialog() == DialogR ...

  9. 【配置文件节点】java世界配置文件节点

    Spring <context:property-placeholder/> 期望:能不能有一种解决方案可以方便我们在一个阶段内不需要频繁书写一个参数的值,而在不同阶段间又可以方便的切换参 ...

  10. git reflog 和git log :no branch git 提交方式

    git reflog 和git log的区别,外加git cherry-pick的一种用法 git reflog 可以查看所有分支的所有操作记录(包括(包括commit和reset的操作),包括已经被 ...