Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
DANANGJ - Number game |
Let us play a number manipulation game where the players are given a sequence of distinct positive integers a[1], a[2], …, a[n] and a positive integer k. Starting with a[1], the players need to perform at most k moves in order to obtain an. At every move, ai can be changed to aj (i ≠ j) if (6 x a[i] + a[j]) is a prime number.
Given a sequence a[1], a[2], …, a[n] and two positive integers k and M, let us denote W to be the number of ways to obtain a[n] from a[1] using at most k moves. Your task is to compute the remainder of W when divided by M.
Input
The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not greater than 20. The following lines describe the data sets.
Each data set consists of two lines where the first line contains 3 space-separated integers n, k, M (n ≤ 20; k,M ≤ 10^12). The second line contains n space-separated positive integers a[1], a[2], …, a[n] (a[i] ≤ 10^9).
Output
For each data set, write on one line the required remainder.
Example
Input: 1
3 2 100
1 5 7 Output: 2
Được gửi lên bởi: | adm |
Ngày: | 2016-10-12 |
Thời gian chạy: | 15s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | ASM32-GCC ASM32 MAWK BC C CSHARP C++ 4.3.2 CPP CPP14 COFFEE LISP sbcl DART FORTH GO JAVA JS-RHINO JS-MONKEY KTLN OCT PAS-GPC PAS-FPC PERL PERL6 PROLOG PYTHON PYTHON3 PY_NBC R RACKET SQLITE SWIFT UNLAMBDA |