Mike and congruence relation
Practice
4.4 (30 votes)
Modular arithmetic
Ad Hoc
Number theory
Easy
Mathematics
Brute Force search
簡単
Problem
54% Success 16522 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Mike wrote the remainder of each number from 1 to n when divided by k. He wants to find how many pairs have equal value, namely how many ordered pairs \((x,y)\) \((1 \le x < y \le n)\) exist such that \(x \equiv y \; (mod \; k)\).

\(\textbf{Input}\)

The first line contains 2 numbers \(n,k\) \((1 \le n,k \le 10^9)\) separated by space.

\(\textbf{Output}\)

Output the number of ordered pairs that satisfy the relation.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
Basics of bit manipulationModular arithmetic
Points:20
22 votes
Tags:
MathematicsModular arithmeticEasy
Points:20
1 votes
Tags:
Easy