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).
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 one line per testcase, the number of pairs (a,b) as described before.
Input: 3 2 3 4 3 1 6 Output: 1 2 0
|Tags||may12 medium rustinpiece|
|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|
Fetching successful submissions