Pairs Forming LCM LightOJ - 1236 (算术基本定理)
题意:
就是求1-n中有多少对i 和 j 的最小公倍数为n (i <= j)
解析:
而这题,我们假设( a , b ) = n ,那么:
n=pk11pk22⋯pkss,
a=pd11pd22⋯pdss, b=pe11pe22⋯pess,
可以确定max(ei,di)=ki, 关于这点 可以自己反证一下
那么ki的组成就是ei与di中一个等于ki,
另一个任取[0,ki-1]中的一个数,
那么就有 2ki 种方案,
由于 ei=di=ki 只有一种,(两种都为ki)
所以第i位方案数为2ki+1,
有序对(a,b)方案数就是(2k1+1)(2k2+1)⋯(2ks+1),
无序对(a,b)方案数就是:{[(2k1+1)(2k2+1)⋯(2ks+1)] + 1}/2
(n,n)已经只有一个,不会重复,所以+1 再除 2。
题解转载至:https://blog.csdn.net/qq_15714857/article/details/48641121
代码:
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define maxn 10000900
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f;
LL primes[maxn/];
bool vis[maxn];
LL ans = ;
void init()
{
mem(vis,);
for(int i=; i<maxn; i++)
if(!vis[i])
{
primes[ans++] = i;
for(LL j=(LL)i*i; j<maxn; j+=i)
vis[j] = ;
}
} int main()
{
init();
int T;
int kase = ;
cin>> T;
while(T--)
{
LL n, res = , cnt = ;
cin>> n;
for(LL i=; i<ans && primes[i] * primes[i] <= n; i++)
{
LL cnt2 = ;
while(n % primes[i] == )
{
n /= primes[i];
cnt2++;
}
if(cnt2 > )
{
res *= (*cnt2 + );
}
}
if(n > )
{
res *= ;
}
printf("Case %d: %lld\n",++kase,res/+);
}
return ;
}
Pairs Forming LCM LightOJ - 1236 (算术基本定理)的更多相关文章
- Pairs Forming LCM LightOJ - 1236 素因子分解
Find the result of the following code: long long pairsFormLCM( int n ) { long long res = 0; fo ...
- G - Pairs Forming LCM LightOJ - 1236 (质因子分解)
题解:这道题要从n的角度来考虑i和j. n可以表示为n=a1^p1*a2^p2*a3^p3.......n=lcm(i,j),那么质因子a1^p1,a1可以在i或者j中,并且p1=max(a1i,a1 ...
- Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...
- 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 ...
- 1236 - Pairs Forming LCM
1236 - Pairs Forming LCM Find the result of the following code: long long pairsFormLCM( int n ) { ...
- Pairs Forming LCM(素因子分解)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/B 全题在文末. 题意:在a,b中(a,b<=n) ...
- Pairs Forming LCM (LCM+ 唯一分解定理)题解
Pairs Forming LCM Find the result of the following code: ; i <= n; i++ ) for( int j = i; j ...
- Pairs Forming LCM
题目: B - Pairs Forming LCM Time Limit:2000MS Memory Limit:32768KB Description Find the result of ...
随机推荐
- ingress-nginx 添加https证书
1.配了一个证书,发现报错: kubectl logs ingress-nginx-controller-96fnv -n ingress-nginx unexpected error vali ...
- 2-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案升级篇(视频总揽)
1-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案升级篇(方案总揽) https://v.youku.com/v_show/id_XNDE0Njk3Njg2OA==. ...
- Random快速产生相同随机数的原因及解决方案
老生常谈,还是那三句话: 学历代表你的过去,能力代表你的现在,学习代表你的将来 十年河东,十年河西,莫欺少年穷 学无止境,精益求精 问题描述:很多时候我们可能需要在极短的时间内生成大量的随机数,但是你 ...
- MySQL主主同步配置
1. MySQL主主配置过程 在上一篇实现了主从同步的基础上,进行主主同步的配置. 这里用node19(主),node20(从)做修改,使得node19和node20变为主主同步配置模式 修改配置文件 ...
- su: 无法设置用户ID: 资源暂时不可用
登录非root用户,报错如下:[root@test ~]# su - appsu: 无法设置用户ID: 资源暂时不可用 或者用ssh 命令连接服务器之后,如果一段时间不操作,再次进入 Terminal ...
- C-代码笔记-输入输出
.ACSII 字符实质和整数存储方式相同 //2018年9月16日01:35:54 # include <stdio.h> int main(void) { '; // printf(&q ...
- 【MOOC EXP】Linux内核分析实验八报告
程涵 原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 进程的切换和系统的一般执行过程 知识点 ...
- 软件工程——移动的HelloWorld
package disiti; import java.awt.Color; import java.awt.Cursor; import java.awt.Font; imp ...
- python函数基础用法
函数是通过赋值传递的,参数通过赋值传递给参数,def语句将创建的一个函数对象 并将其赋值给一个变量名! 函数定义的对象属局部作用域,只在函数内部有效,不会影响全局作用域中的对象! 赋值对象属于局部作用 ...
- numpy行转列
>>> a = np.array([1, 2, 3]) >>> a = a.reshape(-1, 1) #-1表示任意行数,1表示1列 >>> ...