0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paizaラーニング問題集「特殊な2項間漸化式2」を解いてみた

Posted at

▼感想:

前の問題である 特殊な2項間漸化式1 を踏まえて
比較的簡単にコードを書くことができました。

▼コード:

########## 処理0(準備) インプット,リスト定義など ###########

x,d_1,d_2 = map(int,input().split())
Q = int(input())

########## 処理1 漸化式の定義、計算 ##########

a = [x]*(1000+1)

for i in range(2,1000+1):
    
    if i % 2 != 0:
        a[i] = a[i-1] + d_1
    else :
        a[i] = a[i-1] + d_2

########## 処理2 入力kに応じた値を出力 ##########

for _ in range(Q):
    
    k = int(input())
    print(a[k])
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?