The Dragon Type
Practice
3.9 (46 votes)
Approved
Medium
Number theory
Ready
Problem
63% Success 3406 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Dragonite decided to go for hill climbing this weekend, but he doesn't have the map of all the hills. However he can make his own map. Since, well, he's a dragon, du'uh.

There are N hills arranged on a line, each in the form of a vertical line segment with one endpoint on the ground. The hills are numbered with integers from 1 to N from left to right. The ith hill has height hi.

A beautiful set S is set of hills such that for any hi, hj present in set S, (hi * hj)%p!=1.

Note that here i can be equal to j. Here p is any prime integer. To make the map, Dragonite needs maximum possible size of the beautiful set.

Note that two sets are considered different if they contain at least one point which is different. Two sets are considered same if they contain the same points.

Input format:
The first line of input contains two integers N, the number of hills and a prime number p. The next N lines contains the height of the hills.

Output format:
Print the maximum possible size of the beautiful set possible.

Constraints:
2 ≤ N ≤ 2 * 105
1 ≤ hi ≤ 1018
2 < p < 105

References:
enter image description here

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
936 votes
Tags:
MathMedium
Points:30
20 votes
Tags:
ApprovedCombinatoricsMathMediumOpen
Points:30
49 votes
Tags:
MathMediumNumber theorySqrt-Decomposition