Number of solutions
Easy Accuracy: 47.37% Submissions: 19 Points: 2

Given two integers b and p. Find the number of integral solutions to x2 = 1 (mod p) in the closed interval [1, b].

Example 1:

Input:
b = 5, p = 7
Output:
1
Explanation:
12 = 1%7 = 1. 1 is the only possible
solution in the range [1,5].

Example 2:

Input:
b = 8, p = 6
Output:
3
Explanation:
There are 3 possible solutions.
12 = 1%6 = 1
52 = 25%6 = 1
72 = 49%6 = 1


You don't need to read input or print anything. Your task is to complete the function noOfSol() which takes 2 Integers b, and p as input and returns count of numbers in the range [1,b] that give a reamainder of 1 when the squared number is divided with p.

Expected Time Complexity: O(p)
Expected Auxiliary Space: O(1)

Constraints:
1 <= b <= 109
1 <= p <= 105

We are replacing the old Disqus forum with the new Discussions section given below.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  