【Number With The Given Amount Of Divisors 】【CodeForces - 27E】(反素數)
阿新 • • 發佈:2018-12-05
題目:
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的數)。反素數的模板題,之前沒有接觸過,第一次覺得沒有思路,後來慢慢就理解了,關於反素數的求解是參考了大佬的部落格這裡這裡!!!,使用dfs進行遍歷,增加滿足最小成立條件的優化。
ac程式碼:
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; typedef long long ll; const int maxn =1e5+100; ll n; ll ans=1e18; ll num[]={0,2,3,5,7,11,13,17,19,23,29}; void fin(ll v,ll nn,ll p) { if(nn>n) { return ; } if(nn==n) { if(v<ans) ans=v; return ; } for(int i=1;i<=64;i++) { v*=num[p]; if(v>=ans) break; if(nn<n) { fin(v,nn*(i+1),p+1); } } } int main() { scanf("%lld",&n); if(n==1) { printf("1\n"); return 0; } fin(1ll,1ll,1ll); printf("%lld\n",ans); return 0; }