CodeForces 27E
2016-08-21 16:22
411 查看
E. Number With The Given Amount Of Divisorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven the number n, find the smallest positive integer which has exactlyn divisors. It is guaranteed that for the givennthe answer will not exceed 1018.InputThe first line of the input contains integern (1 ≤ n ≤ 1000).OutputOutput the smallest positive integer with exactlyn divisors.ExamplesInput
4Output
6Input
6Output
12
一道想了好久的题目,主要是dfs的建树过程不太清楚,跟学长讨论之后方领悟其精妙之处
注意其剪枝优化
具体应用知识见图片
#include <cstdio>const unsigned long long INF=~0;int prime[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};int n;unsigned long long ans;void dfs(int dept,unsigned long long tmp,int num){if(num>n||dept>15) return;if(num==n&&ans>tmp) {ans=tmp;return;}for(int i=1;i<=63;i++){if(ans/prime[dept]<tmp||num*(i+1)>n) break;dfs(dept+1,tmp*=prime[dept],num*(i+1));}}int main(){while(~scanf("%d",&n)){ans=INF;dfs(0,1,1);printf("%llu\n",ans);}return 0;}
相关文章推荐
- Codeforces 377B . Preparing for the Contest【优先队列】
- Codeforces_158B
- 字典树(+DFS)——Watto and Mechanism ( CodeForces 514C )
- Codeforces 346D
- Codeforces 2B: The least round way【动态规划】
- Codeforces--477Div.2--B
- Codeforces 463D Gargari and Permutations(BFS)
- CodeForces 435C Cardiogram
- codeforces 573b Bear and Blocks
- Codeforces 154D
- codeforces 702C Cellular Network 二分
- 代码实现问题 CodeForces 822B
- Codeforces 463C. Gargari and Bishops
- codeforces 604A Uncowed Forces
- Codeforces 414b Mashmokh and ACM
- CodeForces - 598A
- Codeforces 828D High Load【贪心+求树的最长链】
- Codeforces-739B:Igor and his way to work(BFS+优化)
- Codeforces 109C Lucky Tree 组合计数+dfs
- Codeforces--602A--Two Bases(水)