#SP0000248. Mật khẩu có tổng chữ số nguyên tố (Primewords Revisit)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mật khẩu có tổng chữ số nguyên tố (Primewords Revisit)
Primewords Revisit
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A password consists of exactly decimal digits, each independently chosen from through , including the first digit. It is called a prime-word if the sum of every four consecutive digits is prime.
For instance, the five-digit password 53419 is valid: and are prime.
Count all valid passwords of length modulo . When , there are no blocks of four consecutive digits, and every such password is valid.
Input
The only line contains integer , the password length.
Output
Print a single integer: the number of length- passwords whose every block of four consecutive digits has prime sum, modulo .
Subtasks
- Subtask 1 (20 points): ; each digit is in , including the leading digit.
- Subtask 2 (30 points): ; each digit is in , including the leading digit.
- Subtask 3 (50 points): ; each digit is in , including the leading digit.
Examples
Input
4
Output
3010
Explanation
For , there is only one block of four consecutive digits. The valid prime sums from through are . The counts of four-digit tuples achieving those sums are respectively . Summing gives . Leading zeros are allowed, so a password such as 0002 is counted.