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 :
- Find two co-prime integers such that the first divides A and the second divides B
- Queries to count integers in a range [L, R] such that their digit sum is prime and divisible by K
- Quick ways to check for Prime and find next Prime in Java
- Find coordinates of a prime number in a Prime Spiral
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Find the number of integers from 1 to n which contains digits 0's and 1's only
- Find the first N integers such that the sum of their digits is equal to 10
- Find N integers with given difference between product and sum
- Find three integers less than or equal to N such that their LCM is maximum
- Find n positive integers that satisfy the given equations
- Find all the possible remainders when N is divided by all positive integers from 1 to N+1
- Find a pair with maximum product in array of Integers
- Find the integers that doesnot ends with T1 or T2 when squared and added X
- Find integers that divides maximum number of elements of the array
- Find a Symmetric matrix of order N that contain integers from 0 to N-1 and main diagonal should contain only 0's
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.