The Hash Table
시간 제한1초메모리 제한512 MB
i를 0부터 n-1까지 슬롯 i^2 mod m에 넣을 때 각 슬롯에 이미 있는 원소 수만큼 비용을 내고, 총비용을 구한다.
문제
There is a hash table with slots, numbered from to . Initially the slots are empty.
There are elements, numbered from to , which should be inserted into the hash table in this order.
The hash function is , so the element number will be inserted into the slot numbered .
Because of the strange implementation, inserting an element into a slot costs , where is the number of elements this slot already contains. Please compute the total cost of inserting all these elements into the table.
입력
The first line contains an integer , denoting the number of test cases ().
Each test case is given on a single line with two integers, and (, ).
출력
For each test case, print a single line containing the answer.
힌트
In the first test case, the elements are inserted into slots respectively, incurring costs of .