Linear Congruences
Time limit1sMemory limit512 MB
Given M and b, count pairs (a, m) with 1 <= a <= M and 2 <= m <= M where ax = b (mod m) has at least one solution.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Divide and conquer
- Solved
- No attempts yet
Problem
Given integers and , write a program that counts the pairs that satisfy both conditions below.
- Condition 1: and are integers with and , respectively.
- Condition 2: the linear congruence in has at least one solution.
Input
The first line contains integers and in this order.
Output
Print the number of pairs that satisfy the conditions.
Constraints
- All numbers in the input are integers.