Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: yume_snowy
Problemset: นักบินอวกาศ
Language: cpp
Time: 0.003 second
Submitted On: 2026-09-24 16:41:18
#include <stdio.h>
int main() {
int t;
scanf("%d",&t);
/* sol loop
int height = 0; // ความสูง
int x = 4;
for (int current_t = 1; current_t <= t; current_t++) {
height += x;
x += 6;
}
printf("%d", height);
*/
// observe ว่า height คือ
// 0 4 14 30 52 80...
// + + + + +
// 4 10 16 22
// เคสที่ t = 0 ก็ตอบ 0 ไปเลยก็ได้
// นอกนั้น หาอนุกรม Sn จากสูตร Sn = (n/2)*(a1+an)
// ex. S5 = 5/2 * (4+(4+6*4)) = 5/2 *(32) = 80
// ที่มาสูตรอนุกรมคือ Sn = a1+a2+a3+...+an
// Sn = (a1) + (a1+d) + (a1+2d) + ... (a1+(n-1)d)
// a1*n +(1+2+...(n-1))d
// a1*n + (n-1)(n)(d)/2
// (2a1*n + (n-1)(n)(d))/2
// n((2a1+(n-1)(d)))/2
// n/2 (a1+a1+(n-1)d)
// n/2 (a1 + an)
int height = 0;
if (t > 0) height = (t * (8+6*(t-1)))/2;
printf("%d",height);
}