#SP0000222. Tổng chữ số nguyên tố liên tiếp (Prime Digit Sums)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng chữ số nguyên tố liên tiếp (Prime Digit Sums)
Prime Digit Sums
Source: HackerRank
Version: Phuoc Hung OJ Extended
Problem Statement
Chloe notices that certain groups of consecutive decimal digits have prime sums. She defines three rules for a positive integer:
- The sum of every 3 consecutive digits is prime.
- The sum of every 4 consecutive digits is prime.
- The sum of every 5 consecutive digits is prime.
If the integer has fewer than 3, 4, or 5 digits, the corresponding rule has no group to check. A positive -digit integer cannot start with 0.
Given , count all positive integers having exactly decimal digits that satisfy these rules. Print the result modulo .
Input
The only line contains , the required number of decimal digits.
Output
Print the number of valid -digit positive integers modulo .
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Input
6
Output
95
Explanation
For , examine four length-3 digit groups, three length-4 groups, and two length-5 groups. For example, is valid: the sums for groups of 3 digits are ; for groups of 4 digits they are ; and for groups of 5 digits they are . Every listed sum is prime. Any six-digit integer with a non-prime sum for at least one required group is invalid.
The counts for lengths are respectively . Thus the required six-digit count is 95.