ORDSUM23 - Sums of 2 and 3
Changu and Mangu are brothers. Changu likes 2 and Mangu likes 3. They decided to express each number as sum of 2 and 3.
They need your help. They want you to tell them the number of ways of writing a number as ordered sums of 2 and/or 3.
For example, there are 4 ways to write 8 as an ordered sum of 2s and/or 3s:
- 2 + 2 + 2 + 2
- 2 + 3 + 3
- 3 + 2 + 3
- 3 + 3 + 2
Input
The first line contains T, the number of test cases. It is followed by T lines, each containing the number N.
Output
You have to print the number of ways of writing N as ordered sum of 2 and/or 3. You have to print the answer mod 1000000007.
Example
Input: 3 2 3 8 Output: 1 1 4
Constraints:
T <= 100000
1 <= N <= 1000000
hide comments
Akshat Jain:
2016-06-20 17:07:39
I m solving in O(n), still it gives TLE...Any suggestions?
|
|
ABHIJEET:
2016-06-20 12:37:08
top down is giving seg fault ..any suggestions .. :)
|
|
mis94:
2016-06-20 03:47:14
I wonder why this code crashes when I try to enter 1000000
|
|
chawla_1209:
2016-06-18 10:59:16
enjoyed it :D Last edit: 2016-06-18 11:00:10 |
|
chawla_1209:
2016-06-18 10:59:14
First DP problem. :D Last edit: 2016-06-18 10:59:32 |
|
Sarthak Munshi:
2016-06-17 15:46:49
equal to coin change problem + order matters . one way to put it . easy if you observe the pattern . Last edit: 2016-06-17 15:55:19 |
|
satoruu:
2016-06-16 14:49:00
This is a nice problem for people starting with Dynamic Programming :) |
|
Piyush Kumar:
2016-06-16 12:41:14
If the problem is too easy, should I consider moving it to tutorial?
|
Added by: | Piyush Kumar |
Date: | 2016-06-14 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |
Resource: | Own Problem |