Divisible Pairs

All submissions for this problem are available.
Given N and M Dexter wants to know how many pairs a,b(1 <= a < b <=N) are there such that (a+b) is divisible by M.
For example when N=4 and M=3, there are 2 possible pairs the sum of which is divisible by M and they are (1,2) and (2,4).
Input
First line of input contains T(<=100000) which is the number of test cases. Each of the next T lines contains two integers N(1 <= N <= 10^9) and M(2 <= M <= 10^9).
Output
Output one line per testcase, the number of pairs (a,b) as described before.
Example
Input: 3 2 3 4 3 1 6 Output: 1 2 0
Author:  rustinpiece 
Tester:  subra 
Editorial  http://discuss.codechef.com/problems/DIVPAIR 
Tags  may12 medium rustinpiece 
Date Added:  11032012 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.4, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions