博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Problem12
阅读量:7071 次
发布时间:2019-06-28

本文共 2932 字,大约阅读时间需要 9 分钟。

1.package com.shui.mu.yao.io.algorithm;  2.  3.import java.util.ArrayList;  4.import java.util.List;  5.  6.public class Problem12 {  7.  8.    public static void main(String[] args) {  9.        long start = System.currentTimeMillis();  10.        int x = 500;  11.        int count = 1;  12.        while ((x /= 2) != 0) {  13.            count++;  14.        }  15.        List
seed = new ArrayList
(); 16. seed.add(2); 17. int factor = 2; 18. while (seed.size() < 500) { 19. boolean isPrime = true; 20. for (int s : seed) { 21. if (factor < s) 22. break; 23. if (factor % s == 0) 24. isPrime = false; 25. } 26. if (isPrime) 27. seed.add(factor); 28. factor++; 29. } 30. 31. int N = (int) Math.pow(2, count); 32. int sum = 0; 33. List
list = new ArrayList
(); 34. while (true) { 35. N++; 36. sum = (1 + N) / 2 * N; 37. list.clear(); 38. for (int s : seed) { 39. if (sum < s) 40. break; 41. int count_ = 0; 42. int temp = sum; 43. while (temp % s == 0) { 44. count_++; 45. temp = temp / s; 46. } 47. if (count_ != 0) { 48. list.add(new Node(s, count_)); 49. } 50. 51. } 52. int result = 1; 53. for (Node node : list) { 54. result = result * (node.getY() + 1); 55. } 56. if (result > 500) { 57. int re=1; 58. for (Node node : list) { 59. System.out.println("factor:" + node.getX() + "\t" 60. + "count:" + node.getX()); 61. re*=Math.pow(node.getX(), node.getY()); 62. } 63. if(re==sum) 64. System.out.println("this is a true result"); 65. System.out.println("sum:" + sum); 66. System.out.println("N:" + N); 67. break; 68. } 69. 70. } 71. 72. long end = System.currentTimeMillis(); 73. System.out.println("time:" + (end - start) + "ms"); 74. 75. } 76. 77.} 78. 79.class Node { 80. private int x; 81. 82. public int getX() { 83. return x; 84. } 85. 86. public void setX(int x) { 87. this.x = x; 88. } 89. 90. public int getY() { 91. return y; 92. } 93. 94. public void setY(int y) { 95. this.y = y; 96. } 97. 98. private int y; 99. 100. Node(int x, int y) { 101. this.x = x; 102. this.y = y; 103. } 104.}

转载地址:http://yeell.baihongyu.com/

你可能感兴趣的文章
c++操作符重载_12
查看>>
eclipse 安装反编译工具
查看>>
我的Java开发学习之旅------>Java多线程下载文件 实例
查看>>
WireShark简单使用以及TCP三次握手
查看>>
什么是@guid
查看>>
nodeType的12种类型
查看>>
步步为营 .NET 代码重构学习笔记 十三
查看>>
053:Field的常用参数详解:
查看>>
读书笔记之SQL必知必会
查看>>
Jquery获取input表单的内容
查看>>
Paint、Canvas
查看>>
关于读写锁算法的java实现及思考
查看>>
最小堆排序
查看>>
iOS-网络爬虫
查看>>
jira
查看>>
elasticsearch rpm 安装
查看>>
Python基础总结(字符串常用,数字类型转换,基本运算符与流程控制)
查看>>
数据预处理——剔除异常值,平滑,归一化
查看>>
Visual stuido 项目路径的奇怪问题
查看>>
java局部变量和临时变量
查看>>