【数学】【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)\)。

原文地址:https://www.cnblogs.com/yifusuyi/p/9901071.html

时间: 2024-10-03 07:10:44

【数学】【CF27E】 Number With The Given Amount Of Divisors的相关文章

CF 27E Number With The Given Amount Of Divisors

A - Number With The Given Amount Of Divisors Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed

codeforces 27E . Number With The Given Amount Of Divisors 搜索+数论

题目链接 首先要知道一个性质, 一个数x的因子个数等于 a1^p1 * a2^p2*....an^pn, ai是x质因子, p是质因子的个数. 然后就可以搜了 #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #incl

XTU 1242 Yada Number 容斥

Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime integers. Duoxida says an integer is a yada number if the total amount of 2,3,5,7,11,13 in its prime factors is even. For instance, 18=2 * 3 * 3 is no

XTU1242:Yada Number

Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime integers. Duoxida says an integer is a yada number if the total amount of 2,3,5,7,11,13 in its prime factors is even. For instance, 18=2 * 3 * 3 is no

Change the indent between a list bullet or number and text

Keywords: Office Word Applies To: Word 2007 You can adjust the indents in a list to change how the list items line up. NOTE: For information about adjusting line spacing, see Adjust the spaces between lines or paragraphs. What do you want to do? Adju

xtu 1242 Yada Number 打表

Yada Number       Time Limit : 2000 MS   Memory Limit : 65536 KB Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime integers. Duoxida says an integer is a yada number if the total amount of 2,3,5,7,11,

xtu 1242 Yada Number 容斥原理

Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime integers. Duoxida says an integer is a yada number if the total amount of 2,3,5,7,11,13 in its prime factors is even. For instance, 18=2 * 3 * 3 is no

projecteuler----&gt;problem=12----Highly divisible triangular number

title: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of

Project Euler:Problem 12 Highly divisible triangular number

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the fir