天天看點

用java 計算mic,java每日小算法(9)

package test;

import java.util.ArrayList;

import java.util.List;

public class test {

public static boolean overnum(int number) {

List list = new ArrayList();

list.add(1);

boolean flag = false;

int tem = number / 2;

int sum = 0;

int compare = number;

for(int i = 2; i <= tem; i++)

{

if(number == 1)

break;

if(number % i == 0)

{

list.add(i);

}

}

for(int i = 0; i < list.size(); i++)

sum = sum + list.get(i);

if(compare == sum)

flag = true;

return flag;

}

public static void main(String[] args) {

long a = System.currentTimeMillis();

for(int i = 0; i < 1000; i++)

if(overnum(i))

System.out.println(i);

System.out.println(System.currentTimeMillis() - a);

}

}