CF #27E - Number With The Given Amount Of Divisors 已知因子个数求最小
2013-04-01 12:21
453 查看
题意
已知一个数X有K个因子,求最小的X。
解法
搜索剪枝
对于任意整数
其因子个数为:
意味着
因为需要最小的整数 N, 则我们使用小的质因子总是最优.
所以我们枚举
已知一个数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; }
相关文章推荐
- Codeforces Beta Round #27 E. Number With The Given Amount Of Divisors 含n个约数最小数
- Codeforces Beta Round #27 E. Number With The Given Amount Of Divisors 含n个约数最小数
- CodeForces - 27E Number With The Given Amount Of Divisors (DFS+数学)
- E. Number With The Given Amount Of Divisors
- codeforces 27E - Number With The Given Amount Of Divisors (数论 dfs)
- Codeforces 27 E Number With The Given Amount Of Divisors
- CodeForce 27E: Number With The Given Amount Of Divisors(求反素数)
- 大家一起做训练 第一场 E Number With The Given Amount Of Divisors
- Codeforces 27E. Number With The Given Amount Of Divisors (暴力)
- 27E - Number With The Given Amount Of Divisors
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- Codeforces 27E - Number With The Given Amount Of Divisors
- CF-27E - Number With The Given Amount Of Divisors(枚举+dfs)
- E. Number With The Given Amount Of Divisors
- Codeforces Beta Round #27-E. Number With The Given Amount Of Divisors
- CF-27E - Number With The Given Amount Of Divisors(枚举+dfs)
- CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)
- CF27E:Number With The Given Amount Of Divisors(反素数)
- CF 27E Number With The Given Amount Of Divisors
- Ccodeforces 27E Number With The Given Amount Of Divisors(数论+搜索)