package com.shui.mu.yao.io.algorithm; import java.util.ArrayList; import java.util.List; public class Problem12 { public static void main(String[] args) { long start = System.currentTimeMillis(); int x = 500; int count = 1; while ((x /= 2) != 0) { count++; } List<Integer> seed = new ArrayList<Integer>(); seed.add(2); int factor = 2; while (seed.size() < 500) { boolean isPrime = true; for (int s : seed) { if (factor < s) break; if (factor % s == 0) isPrime = false; } if (isPrime) seed.add(factor); factor++; } int N = (int) Math.pow(2, count); int sum = 0; List<Node> list = new ArrayList<Node>(); while (true) { N++; sum = (1 + N) / 2 * N; list.clear(); for (int s : seed) { if (sum < s) break; int count_ = 0; int temp = sum; while (temp % s == 0) { count_++; temp = temp / s; } if (count_ != 0) { list.add(new Node(s, count_)); } } int result = 1; for (Node node : list) { result = result * (node.getY() + 1); } if (result > 500) { int re=1; for (Node node : list) { System.out.println("factor:" + node.getX() + "\t" + "count:" + node.getX()); re*=Math.pow(node.getX(), node.getY()); } if(re==sum) System.out.println("this is a true result"); System.out.println("sum:" + sum); System.out.println("N:" + N); break; } } long end = System.currentTimeMillis(); System.out.println("time:" + (end - start) + "ms"); } } class Node { private int x; public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } private int y; Node(int x, int y) { this.x = x; this.y = y; } }