Problem code: DIVPAIR
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
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions