Equal remainders
Time limit1sMemory limit1024 MB
Given N distinct integers A and a value K, find the smallest positive M so that s^K lies in S(A^M) for every s in S(A), modulo 1e9+7, or -1.
- Level
Hard8 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
The definition of remainders and divisibility is extended from positive integers to all integers as follows.
- For an integer and a positive integer , the remainder of divided by is the value with for which holds for some integer . This is written .
- An integer is divisible by a positive integer when the remainder of divided by is .
Given a set of integers and a positive integer , define as follows.
Here for and .
In plain terms, is the set of positive integers such that every element of leaves the same nonzero remainder when divided by , and every element of is coprime to . is the set of numbers that have the same sign as each element of and whose absolute value is that element's absolute value raised to the power .
Given a set of distinct integers and a nonnegative integer , find the smallest positive integer such that
Input
The first line contains positive integers () and (), separated by a space.
The second line contains distinct integers () in ascending order, separated by spaces.
Output
Print the smallest positive integer that satisfies the condition, modulo , since the answer can be very large.
If no such exists, print -1 instead.