【Bzoj1053】反素數ant

定理:一個數約數個數=所有素因子的次數+1的乘積

然後得一個2000000000以內的數字不會有超過12個素因子

在一個因子數爲n的集合中,這個集合中最小的數就是一個反質數。

所以我們只要找出小於n的數中因數個數最多的最小數。


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long LL;

const LL Inf = (unsigned)(-1) >> 1;

int prm[10]={2,3,5,7,11,13,17,19,23,29};
int num;
LL Ans,n;

void Dfs(int x,int y,LL z){
    if(y > num) num = y,Ans = Inf;
    if(y == num) Ans = min(Ans,z);
    if(x >= 10) return;
    for(int i=0;z<=n;z*=prm[x],i++) Dfs(x+1,y*(i+1),z);
}

int main(){
    scanf("%lld",&n);Dfs(0,1,1);printf("%lld",Ans);return 0;
}


發佈了72 篇原創文章 · 獲贊 6 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章