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 ...
随机推荐
- GIT 管理修改、删除文件
管理修改 现在,假定你已经完全掌握了暂存区的概念.下面,我们要讨论的就是,为什么Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件. 你会问,什么是修改?比如你新增了一行,这就 ...
- React-使用styled-components
1.安装 npm install --save styled-components 2.简单使用 style.js: import styled from 'styled-components'; i ...
- jQuery webcam plugin
jQuery webcam plugin The jQuery webcam plugin is a transparent layer to communicate with a camera di ...
- Topshelf的Ioc实现
在前面使用Topshelf的文章里,我们的工作类TownCrier使用的是无参数的构造函数,满足测试的目的.在实际的开发过程中,我们常常需要使用带有参数的构造函数,就不可避免的使用Ioc的技术.在这里 ...
- hibernate 解决 java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.xxx 这类的问题
<!-- 解决 java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.intern ...
- 利用卷积神经网络(VGG19)实现火灾分类(附tensorflow代码及训练集)
源码地址 https://github.com/stephen-v/tensorflow_vgg_classify 1. VGG介绍 1.1. VGG模型结构 1.2. VGG19架构 2. 用Ten ...
- Puppet常识梳理
Puppet简单介绍 1)puppet是一种Linux/Unix平台下的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统服务等.puppet把这些系统 ...
- Zookeeper Ephemeral结点使用心得
原文地址:https://www.cnblogs.com/linlemo/p/4807178.html 公司里面在拿Zookeeper做命名服务,通过使用ZK,前端只需要根据指定的ZK地址获得相应的资 ...
- cross-env简介
是什么 运行跨平台设置和使用环境变量的脚本 出现原因 当您使用NODE_ENV =production, 来设置环境变量时,大多数Windows命令提示将会阻塞(报错). (异常是Windows上的B ...
- Daily Scrumming* 2015.12.21(Day 13)
一.团队scrum meeting照片 大部分成员编译请假,故今天没有开scrum meeting 二.成员工作总结 姓名 任务ID 迁入记录 江昊 无 无 任务说明: 今日准备编译测验,请假 遇到问 ...