您的位置:首页 > 其它

CF #27E - Number With The Given Amount Of Divisors 已知因子个数求最小

2013-04-01 12:21 453 查看
题意

  已知一个数X有K个因子,求最小的X。

解法

  搜索剪枝

  对于任意整数


  其因子个数为:


  意味着


  因为需要最小的整数 N, 则我们使用小的质因子总是最优.

  所以我们枚举


  

#include<stdio.h>

typedef long long LL;
const LL INF = 1000000000000000010ll;
int p[12] = { 2,3,5,7,11,13,17,19,23,27,29,31};
int N;
void dfs( LL &ans, int i, LL x, int n ){
if( n > N ) return; // 基本减枝
if( n == N && ans > x ) ans = x;
for(int j = 1; j <= 60; j++){
if( ans/p[i] < x ) break;  // 若 ans < x*p[i] , 则当前p[i]的 j次不可能是最优.就没必要往后面枚举了.
dfs( ans, i+1, x*=p[i], n*(j+1) );
}
}
int main(){
while( scanf("%d",&N) != EOF){
LL ans = INF;
dfs( ans, 0, 1, 1 );
printf("%I64d\n", ans );
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: