Given four integers X, Y, X2%P, Y2%P, where P is a prime number. The task is to find prime P.
Note: Answer always exsits.
Input : X = 3, XsqmodP = 0, Y = 5, YsqmodP = 1
Output : 3
When x = 3, x2 = 9, and 9 modulo P is 0. So possible value of p is 3
When x = 5, x2 = 25, and 25 modulo P is 1. So possible value of p is 3
Input : X = 4, XsqmodP = 1, Y = 5, YsqmodP = 0
Output : 5
From above numbers we get,
X2 – XsqmodP = 0 mod P
Y2 – YsqmodP = 0 mod P
Now find all the common prime factors from both the equation, and check if it satisfies the original equation, If it does (one of them will since answer always exists) then that’s the answer.
Below is the implementation of the above approach :
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Permutation of first N positive integers such that prime numbers are at prime indices
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Find Prime Adam integers in the given range [L, R]
- Find two co-prime integers such that the first divides A and the second divides B
- Queries to find whether a number has exactly four distinct factors or not
- Find four factors of N with maximum product and sum equal to N | Set-2
- Find four factors of N with maximum product and sum equal to N
- Find four factors of N with maximum product and sum equal to N | Set 3
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Find the number of ways to divide number into four parts such that a = c and b = d
- Find the area of the shaded region formed by the intersection of four semicircles in a square
- How to check if given four points form a square
- Number of digits in the nth number made of given four digits
- Minimum sum obtained from groups of four elements from the given array
- Median in a stream of integers (running integers)
- Mode in a stream of integers (running integers)
- Quick ways to check for Prime and find next Prime in Java
- Find coordinates of a prime number in a Prime Spiral
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Count all prime numbers in a given range whose sum of digits is also prime
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.