TopcoderArchive
Archive
Algorithm problem

SegmentDisplay

Problem statement, definition, constraints, and public examples.

Problem Statement

You have a digital display with an infinite number of positions. Each position consists of 7 segments - 4 vertical and 3 horizontal. Lighting certain segments within a position allows you to represent different decimal digits on the display:

                   

You can use the display to represent different non-negative integers. To represent an integer you need to show its digits, in order, on consecutive display positions. The integers you represent on the display cannot have extra leading zeros.

You are given an int n, and your task is to count each integer that can be represented by lighting exactly n segments. Return this count modulo 1,000,000,007.

Definition

Class:
SegmentDisplay
Method:
howManyNumbers
Parameters:
int
Returns:
int
Method signature:
int howManyNumbers(int n)
(be sure your method is public)

Constraints

  • n will be between 0 and 500000, inclusive.

Examples

  1. 2
    Returns: 1
    Using 2 segments you can represent an integer 1.
  2. 1
    Returns: 0
    One segment is not enough to display even one digit.
  3. 6
    Returns: 7
    Using 6 segments you can represent integers 0, 6, 9, 14, 41, 77, 111.
  4. 10
    Returns: 59
  5. 0
    Returns: 0
Back to all problems