2020年4月15日 星期三

[C_MM228-易] 圖形數

[C_MM228-易] 圖形數

成績: 0 / 倒扣: 0.8

問題描述:

圖形數

Type

1st

2nd

3rd

4th

5th

6th

三角數

Value

1

3

6

10

15

21

四角數

Value

1

4

9

16

25

36

五角數

Value

1

5

12

22

35

51

nth x - gonal number 表示

輸入說明:

ex:

輸入 input.txt 含多角數 x 階層數 n

5 5

結果請寫入 output.txt

35

輸出輸入測試資料

1 1

1

3 2

3

3 3

6

3 4

10

4 2

4

4 3

9

4 4

16


while True:
    try:
        x, n = map(int,input().split())
        num = 0
        end = (n - 1)*(x - 2) + 1
        step = x-2 if x-2 > 0 else 1
        for i in range(1, end+1, step):
            num += i
        print(num)
    except(EOFError):
        break

沒有留言:

張貼留言