您的位置:首页 > 其它

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
4
Output
6
Input
6
Output
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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: