Q = gets.to_i N = Q.times.map { gets.to_i } dp = Array.new(1_000_010, 0) dp[1] = 0 dp[2] = 0 dp[3] = 0 dp[4] = 1 5.upto(1_000_000) do |k| dp[k] = dp[k - 1] + dp[k - 2] + dp[k - 3] + dp[k - 4] dp[k] %= 17 end N.each do |n| puts dp[n] end