Moses Needs Help
View as PDFMoses is planning something and needs your help. Moses has recently been admitted to the Computer Science program at the University of Waterloo. However, the University of Waterloo has been notified that many of their new students enrolled in the Computer Science program are unworthy. To distinguish between the worthy and the unworthy, all applicants have received a math entrance exam. Moses, who is an excellent student, has correctly completed all problems except the last one. He knows that solving all problems will guarantee acceptance to the University of Waterloo but despite being talented in every way possible, Moses is unable to solve the last problem and he requires your help to do so.
Moses is given a function  where 
 is defined if 
 
. All 
 that is defined will have integer values.
For all pairs of integers  such that 
, 
 also has the property that 
 where 
 for some positive integer 
 and 
 
 such that 
 is maximized.
In other words, to calculate , first find the product of 
 and 
. Then, divide the largest factor that can be represented as 
 for some positive integer 
 and 
, where the result is minimized.
He is also given the values  
 where 
.
Moses needs your help to calculate the value , modulo 
.
Constraints
 is guaranteed to be prime.
Subtask 1 [10%]
Subtask 2 [10%]
Subtask 3 [80%]
No additional constraints.
Input Specification
The first line of the input contains  
 and 
 
.
The next line contains  integers, the 
 of which is 
.
Output Specification
Output , modulo 
.
Sample Input 1
4 2
24 15 7 3
Sample Output 1
210
Comments