【數學】【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}\)
2、若\(c_i\)不是單調不升,不妨設\(c_i~<~c_{i+1}\),則將兩指數交換,\(x\)會變小。同上可證因數個數不變。於是交換後答案更優,這與\(x\)是最小的有\(n\)個因子的數矛盾。
證畢。
於是發現答案的唯一分界式,\(2\)一定會出現且指數最大。考慮\(2^{64}\)已經大於\(10^{18}\),所以指數最多為\(64\)。又發現前15個質數連乘的答案已經大於\(10^{18}\)
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