Skip to content
Onsite

Ways to Sum to N Using 1, 2 and 5

MediumP3Coding

Count the ways to write n as a sum of 1s, 2s and 5s where the order of the terms matters. For example n = 3 has 3 ways: 1+1+1, 1+2 and 2+1. Zero has one way (the empty sum).

Example 1

Input
n = 3
Output
3
Why
1+1+1, 1+2 and 2+1.

Example 2

Input
n = 1
Output
1

Example 3

Input
n = 0
Output
1

Constraints

  • 0 <= n <= 60
  • The answer fits in a 53-bit integer.

Hints

Run checks the 3 visible tests, Submit all 11.