【CodeForces - 27E】Number With The Given Amount Of Divisors (數論,數學,反素數)
題幹:
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactly n
Examples
Input
4
Output
6
Input
6
Output
12
題目大意:
給定一個正整數n,求一個最小的正整數,使得它的因子個數恰為n。保證答案不超過1018
解題報告:
這題用到了一個概念叫反素數、、學習了一波。,但是其實就算沒有這個概念,做法也很顯然吧,,做個唯一分解這題就做完了。知識點在下面附上了。
AC程式碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; ll biao[55] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; ll minn = 1e18+5; ll n; void dfs(ll dep,ll tmp,ll cur) { if(cur > n) return ; if(cur==n) minn = min(tmp,minn); for(ll i = 1; i<=63; i++) { if(minn < tmp * biao[dep]) break; tmp = tmp * biao[dep]; dfs(dep+1,tmp,cur*(i+1)); } } int main() { int t; cin>>n; dfs(0,1,1); printf("%lld\n",minn); return 0 ; }
知識點:反素數:來源連結
今天要我要講的是反素數,在ACM中也算是常見的考點,那麼對於搞ACM的同學來說,很有必要搞清楚它,所以接下
來我會很詳細地講解。
在講解反素數之前,我們先來看反素數的概念。
反素數的定義:對於任何正整數,其約數個數記為,例如,如果某個正整數滿足:對任意的正整
數,都有,那麼稱為反素數。
從反素數的定義中可以看出兩個性質:
(1)一個反素數的所有質因子必然是從2開始的連續若干個質數,因為反素數是保證約數個數為的這個數儘量小
(2)同樣的道理,如果,那麼必有
在ACM競賽中,最常見的問題如下:
(1)給定一個數,求一個最小的正整數,使得的約數個數為
(2)求出中約數個數最多的這個數
從上面的性質中可以看出,我們要求最小的,它的約數個數為,那麼可以利用搜索來解。
以前我們求一個數的所有因子也是用搜索,比如,以每一個為樹的一層建立搜尋樹,深度為
以為例進行說明,建樹如下:
可以看出從根節點到每一個葉子結點這條路徑上的所有數字乘起來都是12的約數,所以12有6個約數。