Statistics

Problem Statement for "UnsealTheSafe"

Problem Statement

This problem contains an image that can be viewed in the applet.

A door of a safe is locked by a password. Josh witnessed an employee opening the safe. Here is the information Josh spied.

  1. The password is a sequence containing exactly N digits..
  2. The password is entered using the keypad shown in the picture below.
  3. Every pair of neighboring digits in the password is adjacent on the keypad. Two digits are adjacent on the keypad if they are distinct and have a common edge.

Josh has evil intentions of unsealing the safe, but before he can realize his plan, he wants to know how many different passwords exist. Given the value for N, return the number of possible passwords that satisfy all the constraints given above.

Definition

Class:
UnsealTheSafe
Method:
countPasswords
Parameters:
int
Returns:
long
Method signature:
long countPasswords(int N)
(be sure your method is public)

Constraints

  • N will be between 2 and 30, inclusive.

Examples

  1. 2

    Returns: 26

    if the first button is 1, the second button can be either 2 or 4 if the first button is 2, the second button can be either 1, 3 or 5 if the first button is 3, the second button can be either 2 or 6 if the first button is 4, the second button can be either 1, 5 or 7 if the first button is 5, the second button can be either 2, 4, 6 or 8 if the first button is 6, the second button can be either 3, 5 or 9 if the first button is 7, the second button can be either 4, 8 or 0 if the first button is 8, the second button can be either 5, 7 or 9 if the first button is 9, the second button can be either 6 or 8 if the first button is 0, the second button can be 7 only

  2. 3

    Returns: 74

  3. 25

    Returns: 768478331222

  4. 4

    Returns: 210

  5. 5

    Returns: 600

  6. 6

    Returns: 1710

  7. 7

    Returns: 4882

  8. 8

    Returns: 13926

  9. 9

    Returns: 39746

  10. 10

    Returns: 113406

  11. 11

    Returns: 323638

  12. 12

    Returns: 923502

  13. 13

    Returns: 2635406

  14. 14

    Returns: 7520334

  15. 15

    Returns: 21460630

  16. 16

    Returns: 61240062

  17. 17

    Returns: 174759014

  18. 18

    Returns: 498693678

  19. 19

    Returns: 1423106470

  20. 20

    Returns: 4060990974

  21. 21

    Returns: 11588718614

  22. 22

    Returns: 33069692814

  23. 23

    Returns: 94369903558

  24. 24

    Returns: 269294999646

  25. 26

    Returns: 2192938314414

  26. 27

    Returns: 6257916269734

  27. 28

    Returns: 17857659623934

  28. 29

    Returns: 50959818439094

  29. 30

    Returns: 145419506315214

  30. 30

    Returns: 145419506315214

  31. 29

    Returns: 50959818439094


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: