Strongbox
Time limit1sMemory limit128 MB
Given that only the last of k tried dial positions opens a safe, find the maximum possible number of opening positions consistent with the closure rule (x+y) mod n.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Brute force
- Solved
- No attempts yet
Problem
Byteasar tests and certifies anti-burglary devices. He has just received a new kind of strongbox to test: a combinatorial safe. It is opened with a rotary dial, just like an ordinary combination safe, but the way it opens is different.
The dial can be set to different positions, numbered to . Some of these positions open the safe and the others do not. The set of opening positions has the following combinatorial property, which gives the safe its name: if and are both opening positions, then is an opening position as well. This holds for too.
Byteasar tried distinct positions . The first of them, , did not open the safe; only the last one, , did. He does not intend to try any of the remaining positions. Using only what he has learned from the positions he tried, determine the maximum possible number of positions that open the safe.
Input
The first line contains two integers and separated by a single space, where and .
The second line contains distinct integers separated by single spaces, where .
The input is guaranteed to correspond to some combinatorial safe consistent with the description above: there exists a safe that positions do not open and position does.
Output
Print a single integer: the maximum number of dial positions that can open the safe.