atcoder#ARC144F. [ARC144F] Arithmetic Sequence Nim
[ARC144F] Arithmetic Sequence Nim
Score : points
Problem Statement
You are given a positive integer , a non-negative integer (), and a sequence of positive integers .
A set of positive integers is defined as .
Alice and Bob will play a game against each other. They will alternate turns performing the following operation, with Alice going first:
- Choose a pair of an index () and a positite integer such that . Change to . If there is no such , the current player loses and the game ends.
Find the number, modulo , of pairs that Alice can choose in her first turn so that she wins if both players play optimally in subsequent turns.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the number, modulo , of pairs that Alice can choose in her first turn so that she wins if both players play optimally in subsequent turns.
3 1 0
5 6 7
3
We have . Three pairs satisfy the condition: , , .
5 10 3
5 9 18 23 27
3
We have . Three pairs satisfy the condition: , , .
4 10 8
100 101 102 103
0
Alice cannot win even if she plays optimally. Thus, zero pairs satisfy the condition.
5 2 1
111111111111111 222222222222222 333333333333333 444444444444444 555555555555555
943937640
pairs satisfy the condition. Print the count modulo .