回答編集履歴
2
「みた」が誤変換になってたのをひらがなに直したはずなんだがな…?
test
CHANGED
File without changes
|
1
コード
test
CHANGED
@@ -1,3 +1,69 @@
|
|
1
1
|
mainメソッドで、nが0のままforループに入っているため、一度もループに入れません。
|
2
2
|
|
3
3
|
10000までであるならnを10000にするべきでは?
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
約数の総和を求めるメソッドを他と違えてみた
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```java
|
12
|
+
|
13
|
+
public static void main(String[] args) {
|
14
|
+
|
15
|
+
for (int i = 1; i <= 10000; i++) {
|
16
|
+
|
17
|
+
int j = sumOfDivisor(i);
|
18
|
+
|
19
|
+
if (i < j && sumOfDivisor(j) == i) {
|
20
|
+
|
21
|
+
System.out.println(i + " " + j);
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public static int sumOfDivisor(int a) {
|
32
|
+
|
33
|
+
int c = a;
|
34
|
+
|
35
|
+
int sum = 1;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
for (int i = 2; c >= i * i; i++) {
|
40
|
+
|
41
|
+
int multi = 1;
|
42
|
+
|
43
|
+
int tempSum = 1;
|
44
|
+
|
45
|
+
while (c % i == 0) {
|
46
|
+
|
47
|
+
c /= i;
|
48
|
+
|
49
|
+
multi *= i;
|
50
|
+
|
51
|
+
tempSum += multi;
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
sum *= tempSum;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
if (c != 1) {
|
60
|
+
|
61
|
+
sum *= 1 + c;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
return sum - a;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
```
|