【数学】【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 ...
随机推荐
- Unity编辑器扩展 Chapter3--Create Custom Inspector
一.Create Custom Inspector 重绘inspector面板一方面是我们的挂在脚本的窗口变得友好,另一方面可以让其变得更强大,比如添加一些有效性验证. 二.重要说明 1.Editor ...
- Python爬虫下载Bilibili番剧弹幕
本文绍如何利用python爬虫下载bilibili番剧弹幕. 准备: python3环境 需要安装BeautifulSoup,selenium包 phantomjs 原理: 通过aid下载bilibi ...
- Java学习计划
Java学习计划&书单--2018.10.13 W3C Struts教程 W3C Spring教程 W3C Hibernate教程 <深入JavaWeb技术内幕> Java Web ...
- tensorflow中使用mnist数据集训练全连接神经网络-学习笔记
tensorflow中使用mnist数据集训练全连接神经网络 ——学习曹健老师“人工智能实践:tensorflow笔记”的学习笔记, 感谢曹老师 前期准备:mnist数据集下载,并存入data目录: ...
- 剑指Offer66题的总结、目录
原文链接 剑指Offer每日6题系列终于在今天全部完成了,从2017年12月27日到2018年2月27日,历时两个月的写作,其中绝大部分的时间不是花在做题上,而是花在写作上,这个系列不适合大神,大牛, ...
- 如何更改Arcmap里经纬度小数点后面的位数?
customize>arcmap option>data view >round coordinate to 改成想要显示的小数位数
- Python 代码调试技巧
使用 pdb 进行调试 pdb 是 python 自带的一个包,为 python 程序提供了一种交互的源代码调试功能,主要特性包括设置断点.单步调试.进入函数调试.查看当前代码.查看栈片段.动态改变变 ...
- Beta阶段中间产物
空天猎功能说明书:https://git.coding.net/liusx0303/Plane.git 空天猎代码控制:https://coding.net/u/MR__Chen/p/SkyHunte ...
- 【探路者】团队中的每一次感动——Alpha版
我是[探路者]团队的leader翟宇豪.在软件工程课程开始时,当听说有团队作业这个任务时,我个人还是对leader这个角色很期待的.我很希望通过自己的努力,让我所在的团队变得更好,让组里的每一个成员在 ...
- 团队作业——王者光耀:team
光耀101 <光耀101>是福州大学数计学院计算机专业推出的中国首部程序猿脱发养成节目.由张栋担任发起人,刘晨瑶.畅畅担任导师. 该节目召集了你猜多少位选手,通过任务.训练.考核,让选 ...