真因數 => 從1..n/2
建議先寫 d010
---
程式碼如下:
import java.util.Scanner;
class c184 {
static final Scanner in = new Scanner(System.in);
public static void main(String[] args) {
boolean bool = true;
while (bool) {
int n = in.nextInt();
if (n == 0) {
bool = false;
break;
}
if (num(n) == n) {
System.out.println("=" + n);
} else if (num(num(n)) == n) {
System.out.println(num(n));
} else {
System.out.println(0);
}
}
}
static int num(int n) {
int res = 0;
for (int i = 1; i <= n / 2; i++) {
if (n % i == 0) res += i;
}
return res;
}
}