Padovan Sequence
InterviewTime limit1sMemory limit128 MB
For each test case, compute the Nth Padovan number defined by the spiral of equilateral triangles.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
Equilateral triangles are attached one after another in a spiral. The first triangle has side length 1. After that, let be the length of the longest side of the spiral, and attach an equilateral triangle of side length to that side. This step repeats.
The Padovan sequence is the side length of the -th triangle placed in the spiral. The first ten values, through , are 1, 1, 1, 2, 2, 3, 4, 5, 7, 9.
Given , write a program that computes .
Input
The first line contains the number of test cases . Each test case is one line containing an integer . ()
Output
For each test case, print on its own line.