MeetCode
Count Solutions Of ax ≡ b (mod m)
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Run
Submit
Dark
Problem Statement
Solutions
Submissions
Count Solutions Of ax ≡ b (mod m)
Hard
Computer Mathematics
Modular Arithmetic
46 views
Explanation
Complexity
Problem Statement
Count how many x in [0..m-1] satisfy ax ≡ b (mod m).
Input Format
Three integers a b m.
Output Format
One integer count.
Example
Input
4 2 6
Output
2
Constraints
m>0
Input / Output Format
Input Format
Three integers a b m.
Output Format
One integer count.
Constraints
m>0
Examples
Input:
4 2 6
Output:
2
Example Solution (Public)
Computer Mathematics
Let g=gcd(a,m). If b%g!=0 then 0. Else there are g solutions.
Official Solution Code
Wrap
Copy
Let g=gcd(a,m). If b%g!=0 then 0. Else there are g solutions.
Please
login
to submit solutions.
Editor
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Test Cases
Output
Submission Result
Input
4 2 6
Expected Output
2
Compile Output
Error
Output
Please
login
to submit solutions.