atcoder#ARC102A. [ABC108C] Triangular Relationship

[ABC108C] Triangular Relationship

Score : 300300 points

Problem Statement

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

Constraints

  • 1N,K2×1051 \leq N,K \leq 2\times 10^5
  • NN and KK are integers.

Input

Input is given from Standard Input in the following format:

NN KK

Output

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

3 2
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)(3,3,3) satisfy the condition.

5 3
1
31415 9265
27
35897 932
114191