回答編集履歴
4
d
test
CHANGED
@@ -2,16 +2,98 @@
|
|
2
2
|
|
3
3
|
s = 0 # 累積和
|
4
4
|
|
5
|
-
i =
|
5
|
+
i = 0 # 初期値
|
6
6
|
|
7
|
-
while s + i < 500:
|
7
|
+
while s + i + 1 < 500:
|
8
|
+
|
9
|
+
# 500 を超えない場合
|
10
|
+
|
11
|
+
i += 1
|
8
12
|
|
9
13
|
s += i
|
10
14
|
|
15
|
+
|
16
|
+
|
11
|
-
|
17
|
+
print(s, i) # 496 31
|
18
|
+
|
19
|
+
```
|
12
20
|
|
13
21
|
|
14
22
|
|
23
|
+
1+2+…+31 = 496
|
24
|
+
|
25
|
+
1+2+…+32 = 528
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
なので、1~31までの数の和が500を超えない最大の数
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```output
|
34
|
+
|
35
|
+
1 = 1
|
36
|
+
|
37
|
+
1+2 = 3
|
38
|
+
|
39
|
+
1+2+3 = 6
|
40
|
+
|
41
|
+
1+2+3+4 = 10
|
42
|
+
|
43
|
+
1+2+3+4+5 = 15
|
44
|
+
|
45
|
+
1+2+3+4+5+6 = 21
|
46
|
+
|
47
|
+
1+2+3+4+5+6+7 = 28
|
48
|
+
|
15
|
-
|
49
|
+
1+2+3+4+5+6+7+8 = 36
|
50
|
+
|
51
|
+
1+2+3+4+5+6+7+8+9 = 45
|
52
|
+
|
53
|
+
1+2+3+4+5+6+7+8+9+10 = 55
|
54
|
+
|
55
|
+
1+2+3+4+5+6+7+8+9+10+11 = 66
|
56
|
+
|
57
|
+
1+2+3+4+5+6+7+8+9+10+11+12 = 78
|
58
|
+
|
59
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13 = 91
|
60
|
+
|
61
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14 = 105
|
62
|
+
|
63
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15 = 120
|
64
|
+
|
65
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16 = 136
|
66
|
+
|
67
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17 = 153
|
68
|
+
|
69
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18 = 171
|
70
|
+
|
71
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19 = 190
|
72
|
+
|
73
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20 = 210
|
74
|
+
|
75
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21 = 231
|
76
|
+
|
77
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22 = 253
|
78
|
+
|
79
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23 = 276
|
80
|
+
|
81
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24 = 300
|
82
|
+
|
83
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25 = 325
|
84
|
+
|
85
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26 = 351
|
86
|
+
|
87
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27 = 378
|
88
|
+
|
89
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28 = 406
|
90
|
+
|
91
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29 = 435
|
92
|
+
|
93
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30 = 465
|
94
|
+
|
95
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31 = 496
|
96
|
+
|
97
|
+
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32 = 528
|
16
98
|
|
17
99
|
```
|
3
d
test
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
|
7
7
|
while s + i < 500:
|
8
8
|
|
9
|
+
s += i
|
10
|
+
|
9
11
|
i += 1
|
10
|
-
|
11
|
-
s += i
|
12
12
|
|
13
13
|
|
14
14
|
|
2
d
test
CHANGED
@@ -4,11 +4,7 @@
|
|
4
4
|
|
5
5
|
i = 1 # 初期値
|
6
6
|
|
7
|
-
while True:
|
8
|
-
|
9
|
-
|
7
|
+
while s + i < 500:
|
10
|
-
|
11
|
-
break
|
12
8
|
|
13
9
|
i += 1
|
14
10
|
|
@@ -16,6 +12,6 @@
|
|
16
12
|
|
17
13
|
|
18
14
|
|
19
|
-
print(s, i) # 495 3
|
15
|
+
print(s, i) # 495 31
|
20
16
|
|
21
17
|
```
|
1
e
test
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|
|
7
7
|
while True:
|
8
8
|
|
9
|
-
i += 1
|
10
|
-
|
11
9
|
if s + i >= 500:
|
12
10
|
|
13
11
|
break
|
12
|
+
|
13
|
+
i += 1
|
14
14
|
|
15
15
|
s += i
|
16
16
|
|