Logo
(追記) (追記ここまで)

7651번 - G-Avoiding Sequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB176654.545%

문제

Given a set of distinct integers S and an integer G, we call a sequence of integers a G-Avoiding Sequence if the following two conditions hold:

  1. the sequence is a permutation of the elements of S; and
  2. for any two consecutive elements A and B in the sequence, A − B is not divisible by G.

Compute the number of G-Avoiding Sequences modulo the prime 1,234,567,891.

입력

The input consists of several test cases. The first line of each test case contains two integers N (1 ≤ N ≤ 200), the size of S, and G (1 ≤ G ≤ 1,000). The next line will contain N integers, which are the elements of S and between 0 and 106. Input is followed by a single line with N = G = 0, which should not be processed.

출력

For each test case, output a single line containing the number of G-Avoiding Sequences modulo the prime 1,234,567,891.

제한

예제 입력 1

4 3
1 2 3 4
3 100
10 110 42
0 0

예제 출력 1

12
2

힌트

출처

University > Stanford Local ACM Programming Contest > SLPC 2010 Round Two G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /