#SP0000247. Tính đa dạng của phân tích thừa số nguyên tố (The Diversity of Prime Factorization)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tính đa dạng của phân tích thừa số nguyên tố (The Diversity of Prime Factorization)
The Diversity of Prime Factorization
Source: AOJ
Version: Phuoc Hung OJ Extended
Problem Statement
A machine factorizes an integer as
$$M=p_1^{e_1}p_2^{e_2}\cdots p_K^{e_K},\qquad p_1<p_2<\cdots<p_K,$$where every is prime and every exponent . The machine outputs tokens in increasing order of : it outputs only when , and outputs two consecutive tokens when .
There is no separator distinguishing primes from exponents. Different integers may therefore produce the same sequence. Given the printed sequence , count distinct integers that could produce it. Print if no such integer exists, and take the result modulo .
Input
- The first line contains , the number of output tokens produced by the machine, not the original integer .
- The second line contains exactly integers in their output order.
Output
Print the number of distinct integers producing exactly the given token sequence, modulo .
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
3
2 3 3
Output
2
Explanation
For tokens , there are exactly two legal partitions. Split as [2,3] [3]: this encodes . Or split as [2] [3,3]: this encodes . Each block begins with a prime, the primes increase strictly, and the two encoded integers differ. There are no other legal partitions, so the answer is 2.