【数学】【CF27E】 Number With The Given Amount Of Divisors
Description
给定一个正整数\(n\),输出最小的整数,满足这个整数有n个因子
Input
一行一个整数\(n\)
Output
一行一个整数,代表答案。
Hint
\(1~\leq~n~\leq~1000\)。保证答案不超过\(10^{18}\)
Solution
经典题。
引理:
对于一个唯一分解式形如\(x=p_1^{c_1}p_2^{c_2}p_3^{c^3}\cdots p_k^{c_k}\)的数字\(x\),则其因数个数为\(\prod(c_i+1)\)。
证明:
考虑乘法原理,第\(i\)项的指数有\(0~\sim~c_i\)共\(c_i+1\)种方式,根据唯一分解定理的逆定理,每一项指数不同所得到的数是不同的。于是根据乘法原理,其因数个数为\(\prod(c_i+1)\)。
证毕。
定理:
考虑一个因数个数为\(n\)的最小整数\(x\),则它的唯一分解式\(x=p_1^{c_1}p_2^{c_2}p_3^{c^3}\cdots p_k^{c_k}\)中,不妨设\(p_1~<~p_2~<~p_3~<~\cdots~<~p_k\),则一定满足:\(p_1=2\),且\(\forall ~i~>~1\),\(p_i\)是大于\(p_{i-1}\)的第一个质数,同时\(\forall~i~\in~[1,k)\),\(c_i~\leq~c_{i+1}\)。
证明:
1、若\(p\)在质数表上不是连续的,不妨设\(p_i~<~q~<p_{i+1}\),则将\(p_{i+1}\)替换为\(q\),\(x\)会变小,因为\(c_{i+1}\)不变,根据引理,因数个数不变。于是替换为\(q\)答案更优,这与\(x\)是最小的有\(n\)个因子的数矛盾。
2、若\(c_i\)不是单调不升,不妨设\(c_i~<~c_{i+1}\),则将两指数交换,\(x\)会变小。同上可证因数个数不变。于是交换后答案更优,这与\(x\)是最小的有\(n\)个因子的数矛盾。
证毕。
于是发现答案的唯一分界式,\(2\)一定会出现且指数最大。考虑\(2^{64}\)已经大于\(10^{18}\),所以指数最多为\(64\)。又发现前15个质数连乘的答案已经大于\(10^{18}\),所以质数最多是15个。于是爆搜一下,分别进行一下可行性剪枝和最优性剪枝,即可通过本题。
Code
#include<cstdio>
#define rg register
#define ci const int
#define cl const long long
typedef long long int ll;
template <typename T>
inline void qr(T &x) {
rg char ch=getchar(),lst=' ';
while((ch > '9') || (ch < '0')) lst=ch,ch=getchar();
while((ch >= '0') && (ch <= '9')) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
if(lst == '-') x=-x;
}
namespace IO {
char buf[120];
}
template <typename T>
inline void qw(T x,const char aft,const bool pt) {
if(x < 0) {x=-x,putchar('-');}
rg int top=0;
do {IO::buf[++top]=x%10+'0';} while(x/=10);
while(top) putchar(IO::buf[top--]);
if(pt) putchar(aft);
}
template <typename T>
inline T mmax(const T a,const T b) {return a > b ? a : b;}
template <typename T>
inline T mmin(const T a,const T b) {return a < b ? a : b;}
template <typename T>
inline T mabs(const T a) {return a < 0 ? -a : a;}
template <typename T>
inline void mswap(T &_a,T &_b) {
T _temp=_a;_a=_b;_b=_temp;
}
const int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
int n;
ll ans=1000000000000000001;
void dfs(ll,int,int,int);
int main() {
qr(n);
dfs(1ll,0,64,1);
qw(ans,'\n',true);
return 0;
}
void dfs(ll now,int cur,int p,int cnt) {
if(cnt > n) return;
if(now <= 0ll) return;
if(now > ans) return;
if(cur > 15) return;
if(cnt == n) {ans=now;return;}
for(int i=1;i<=p;++i) {
dfs(now*=prime[cur],cur+1,i,cnt*(i+1));
}
}
Summary
对于一个唯一分解式形如\(x=p_1^{c_1}p_2^{c_2}p_3^{c^3}\cdots p_k^{c_k}\)的数字\(x\),则其因数个数为\(\prod(c_i+1)\)。
【数学】【CF27E】 Number With The Given Amount Of Divisors的更多相关文章
- 数论 CF27E Number With The Given Amount Of Divisors
求因子数一定的最小数(反素数) #include<iostream> #include<string> #include<cmath> #include<cs ...
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- E. Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- Codeforces 27E. Number With The Given Amount Of Divisors (暴力)
题目链接:http://codeforces.com/problemset/problem/27/E 暴力 //#pragma comment(linker, "/STACK:1024000 ...
- codeforces 27E . Number With The Given Amount Of Divisors 搜索+数论
题目链接 首先要知道一个性质, 一个数x的因子个数等于 a1^p1 * a2^p2*....an^pn, ai是x质因子, p是质因子的个数. 然后就可以搜了 #include <iostrea ...
- Codeforces Beta Round #27 E. Number With The Given Amount Of Divisors 含n个约数最小数
http://codeforces.com/problemset/problem/27/E RT,求含n个约数的最小的数 我们设答案p = 2^t1 * 3^t2 * -- * p^tk(其中p是第k ...
- 大家一起做训练 第一场 E Number With The Given Amount Of Divisors
题目来源:CodeForce #27 E 题目意思和题目标题一样,给一个n,求约数的个数恰好为n个的最小的数.保证答案在1018内. Orz,这题训练的时候没写出来. 这道题目分析一下,1018的不大 ...
- codeforces 27 E. Number With The Given Amount Of Divisors(数论+dfs)
题目链接:http://codeforces.com/contest/27/problem/E 题意:问因数为n个的最小的数是多少. 题解:一般来说问到因数差不多都会想到素因子. 任意一个数x=(p1 ...
随机推荐
- android 签名相关
查看keystorekeytool -list -v -keystore debug.keystoreapk签名不带别名 apksigner sign --ks debug.keystore test ...
- Python字符串/元祖/列表/字典互转
#-*- coding:UTF-8 -*- #author:RXS002 #1.字典 dict = {'name':'Zara','age':7,'class':'First'} #字典转换为字符串, ...
- springboot 集成 swagger
1. 首先配置swaggerConfigpackage com.lixcx.lismservice.config; import com.lixcx.lismservice.format.Custom ...
- Python3【基础】-表达式与运算符
一.什么是表达式? 1+2*3就是一个表达式,这里的加号和乘号叫做运算符,1.2.3叫做操作数.1+2*3计算的结果是7,计算结果可以存到一个变量中,即:res = 1 + 2 * 3. 所谓的表达式 ...
- React 初学
React.createClass({}); getInitialState,this.setState({}); {}解读代码块,外层不要加引号,比如onChange={this.handleCha ...
- 20181113-7 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 04
作业要求:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2386] 版本控制:[https://git.coding.net/lglr2 ...
- 关于算法的时间复杂度O(f(n))
(一)算法时间复杂度定义: 在进行算法分析时,语句总的执行次数T(n)是关于问题规模n的函数,进而分析T(n)随n的变化情况并确定T(n)的数量级.算法的时间复杂度,也就是算法的时间量度,记作:T(n ...
- struts2 action json(还有servlet的)
http://yshjava.iteye.com/blog/1333104 留着 版权声明:本文为博主原创文章,未经博主允许不得转载.
- Spring的事务到底该给Dao配置还是给Service配置
Spring的事务到底该给Dao配置还是给Service配置 Spring事务为业务逻辑进行事务管理,保证业务逻辑上数据的原子性. 事务得根据项目性质来细分:事务可以设置到三个层面(dao层.serv ...
- QQueue与QStack使用
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QQueue与QStack使用 本文地址:http://techieliang.com ...