设为首页 加入收藏

TOP

URAL 1748. The Most Complex Number 反素数
2015-07-20 17:50:42 来源: 作者: 【 】 浏览:1
Tags:URAL 1748. The Most Complex Number 素数

题目来源:URAL 1748. The Most Complex Number

题意:求一个小于等于n的因子最多的数

思路:搜索+剪枝

#include 
  
   
#include 
   
     using namespace std; typedef unsigned __int64 LL; LL prime[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; LL num, sum, n; void dfs(int p, int q, LL x, LL y) { if(p >= 16) return; if(x > n) return; if(y > sum) { num = x; sum = y; } if(y == sum && num > x) num = x; for(int i = 1; i <= q; i++) { double tmp = (double)x; if(tmp*prime[p] > n) break; dfs(p+1, i, x *= prime[p], y*(1+i)); } } int main() { int T; scanf("%d", &T); while(T--) { scanf("%I64u", &n); sum = 0; dfs(0, 60, 1, 1); printf("%I64u %I64u\n", num, sum); } return 0; }
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇nyist oj 171 聪明的kk (动态规划.. 下一篇剑指offer面试题31:连续子数组的..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

Shell 基本运算符 -
Shell 函数 | 菜鸟教
Linux 常用命令集合
socket 编程如何实现
Python创建简易的Soc