Mike and congruence relation

4.4

30 votes
Modular arithmetic, ad-hoc, Number Theory, Easy, Mathematics, Brute-force search, 簡単
Problem

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 exist such that .

The first line contains 2 numbers separated by space.

Output the number of ordered pairs that satisfy the relation.

Sample Input
5 2
Sample Output
4
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The pairs are : .

Editor Image

?