Problem:
Score : 300 points

Problem Statement

You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.
The order of a,b,c does matter, and some of them can be the same.

Constraints

1 \leq N,K \leq 2\times 10^5

N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

Sample Input 1

3 2

Sample Output 1

9

(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.

Sample Input 2

5 3

Sample Output 2

1

Sample Input 3

31415 9265

Sample Output 3

27

Sample Input 4

35897 932

Sample Output 4

114191

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;

namespace IO {
	const int maxn((1 << 21) + 1);

	char ibuf[maxn], *iS, *iT, c;
	int f;

	inline char Getc() {
		return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), iS == iT ? EOF : *iS++) : *iS++;
	}

	template <class Int> inline void In(Int &x) {
		for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
		for (x = 0; c >= '0' && c <= '9'; c = Getc()) x = (x << 1) + (x << 3) + (c ^ 48);
		x *= f;
	}
}

using IO :: In;

int n, l, bit;

struct Info {
	int u, v, w;
};

vector <Info> ans;

inline void Add(int u, int v, int w) {
	ans.push_back((Info){u, v, w});
}

int main() {
	In(l), --l;
	for (n = bit = 1; bit <= l; bit <<= 1) ++n;
	for (int i = 1; i < n; ++i) Add(i, i + 1, 0);
	for (int i = 2; i < n; ++i) Add(i, i + 1, 1 << (n - i - 1));
	for (int i = n; ~i; --i)
		if ((l >> i) & 1) {
			int flg = 0;
			for (int j = i - 1; ~j; --j)
				if ((l >> j) & 1) {
					Add(n - i - 1, n - j - 1, 1 << i);
					flg = 1;
					break;
				}
			if (!flg) Add(n - i - 1, n, 1 << i);
		}
	printf("%d %d\n", n, l = ans.size());
	for (int i = 0; i < l; ++i) printf("%d %d %d\n", ans[i].u, ans[i].v, ans[i].w);
	return 0;
}