package com.shui.mu.yao.io.algorithm;
public class Problem14 {
public static void main(String[] args) {
long starttime = System.currentTimeMillis();
int start = 640000;/**10:123456789往上翻20再翻40..->640000--1280000*/
int end = 1000000;
int[] seed = new int[end];
int max = 0;
int digit = 0;
/**预热10W数据到arr里面 存储seed值*/
for (int i = 2; i < 10000; i++) {
find(end, seed, i);
}
for (int i = start; i < end; i++) {
int number=find(end, seed, i);
if (number > max) {
max = number;
digit = i;
}
}
System.out.println("digit: "+digit+"\t"+"maxCount:"+max);
System.out.println(System.currentTimeMillis() - starttime);
}
private static int find(int end, int[] seed, int i) {
long count = i;
int number = 0;
if(seed[i]>0)
return seed[i];
while (count != 1) {
if(count<end&&seed[(int) count]>0)
{
number+=seed[(int) count];
break;
}
if ((count & 0X0001) == 0) {
count = count >> 1;
} else {
count = (count << 1) + 1 + count;
}
number++;
}
seed[i]=number;
return number;
}
}
Problem14
最新推荐文章于 2024-11-15 18:38:47 发布