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



Sample input:
3 2


Sample output:
9

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if k%2 != 0:
        count = n//k
        print(count**3)
else:
        x=n//k
        y=2*n//k-x
        print(x**3+y**3)

Submission status: Accepted

Solution code:
# C
n, k = map(int, input().split())
count = 0
a = 0
for i in range(1,n+1):
    if i % k == 0:
        count += 1
    elif i % k == k // 2:
        a += 1
if k % 2 == 1:
    print(count**3)
else:
    print(count**3 + a**3)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
n1 = N // K
if K % 2 == 0:
    n2 = N // (K//2) - n1 
else:
    n2 = 0
print(n1**3+n2**3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
baisu, amaru = 0, 0
for i in range(1,n+1):
    if i % k == 0:
        baisu += 1
    elif i % k == k // 2:
        amaru += 1
if k % 2 == 1:
    print(baisu**3)
else:
    print(baisu**3 + amaru**3)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if k%2!=0:
    count=int(n/k)
    print(count**3)
else:
    x=int(n/k)
    y=int(2*n/k)-x
    print(x**3+y**3)

Submission status: Accepted

Solution code:
n, k = [int(x) for x in input().split()]
count = 0
a = int(n / k)
count += (a + a * (a-1) * 3 + a * (a-1) * (a-2))
if k % 2 == 0:
    b = int(n / (int(k / 2))) - a
    count += (b + b * (b-1) * 3 + b * (b-1) * (b-2))
print(count)

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  N, K = map(int, input().split())
  
  if K % 2 == 1:
    ans = (N // K)**3
  else:
    ans = ((N + K//2) // K)**3 + (N // K)**3
    
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
a, b = 0, 0
for i in range(1, N+1):
  if(i%K == 0):
    a += 1
if(K%2 == 0):
  for i in range(1, N+1):
    if(i%K == K//2):
      b += 1
print(a**3 + b**3)

Submission status: Accepted

Solution code:
class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))

    def solve(self):
        total = 0
        total += self.case_zero()
        if self.k % 2 == 0:  # k is even
            total += self.case_k2()
        print(total)

    def case_zero(self):
        multiples = self.n // self.k
        return multiples ** 3
    
    def case_k2(self):
        multiples = 0
        for i in range(1, self.n+1):  # i = 1 .. n
            if i % self.k == self.k/2:
                multiples += 1
        return multiples ** 3


if __name__ == "__main__":
    s = Solver()
    s.solve()

Submission status: Accepted

Solution code:
#-*- coding:utf-8 -*-
"""
整数N,Kが与えられます。
N以下の正の整数の組(a,b,c)であって、a+b,b+c,c+aがすべてKの倍数であるようなものの個数を求めてください。
ただし、a,b,cの順番を入れ替えただけの組も異なるものとして数えます。
また、a,b,cの中に同じものがあっても構いません。
"""


def main(str):
    num = str.split()
    N = int(num[0])
    K = int(num[1])
    if(K%2 != 0):
        cnt = 0
        for a in range(1, N+1):
            if(a%K == 0):
                cnt += 1
        cnt = cnt ** 3

    else:
        cnt1 = 0
        cnt2 = 0
        for a in range(1, N+1):
            if(a%K == 0):
                cnt1 += 1
        for a in range(1, N+1):

            if(a%K == K/2):
                cnt2 += 1

        cnt = cnt1 ** 3 + cnt2 ** 3

    print(cnt)


if __name__ == "__main__":
    main(input())

Submission status: Accepted

Solution code:
def func():
    pass


def main():
    n, k = map(int, input().split())
    if k % 2 == 1:
        a_c = n // k
        print(a_c ** 3)
    else:
        p1 = (n // k) ** 3

        kh = k // 2
        p2 = ((n // kh) - (n // k)) ** 3
        print(p1 + p2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(N, K):
    ans = 0
    k = len([n for n in range(1, N + 1) if n % K == 0])
    ans += k * k * k
    if K % 2 == 0:
        k = len([n for n in range(1, N + 1) if n % K == K // 2])
        ans += k * k * k

    return ans

if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    print(solve(N, K))

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,K = map(int, input().split())

if K % 2 == 0:
    kinds_mod_0 = N//K
    kinds_mod_half = 0
    for i in range(1,N+1):
        if i % K == K//2:
            kinds_mod_half+=1
    print( kinds_mod_0**3 + kinds_mod_half**3)
else:
    kinds_mod_0 = N//K
    print(kinds_mod_0 ** 3)
    # for i in range(1, N+1):
    #     if i % K == 0:

Submission status: Accepted

Solution code:
import sys
n, k = map(int, input().split())

bai = 1
k_arr = []
while bai * k <= n:
    k_arr.append(bai * k)
    bai += 1


if k % 2 == 0:
    bai2 = 1
    k_arr2 = []
    k_arr2_len = 0 - len(k_arr2)
    while bai2 * k/2 <= n:
        k_arr2.append(bai2 * k/2)
        bai2 += 1
        k_arr2_len = len(k_arr2) - len(k_arr)
    print(len(k_arr)*len(k_arr)*len(k_arr) + k_arr2_len*k_arr2_len*k_arr2_len)

else:
    print(len(k_arr)*len(k_arr)*len(k_arr))

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
a, b = 0, 0
if(K%2 == 0):
  for i in range(1, N+1):
    if(i%K == 0):
      a += 1
    elif(i%K == K//2):
      b += 1
else:
  for i in range(1, N+1):
    if(i%K == 0):
      a += 1
print(a**3 + b**3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

m =  n // k

count = m ** 3

if k % 2 == 0:
    if m*k + k/2 <= n:
        count += (m+1) ** 3
    else:
        count += m**3

print(count)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
if K%2==1:
    print((N//K)**3)
else:
    print((N//(K//2)-N//K)**3+(N//K)**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
if k%2==1:print((n//k)**3)
elif k%2==0:print((n//k)**3 + (n//(k//2) - n//k)**3 )

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
def f(n, k):
    return int(n/k)

if k%2:
    print(f(n,k)**3)
else:
    l = k//2
    p = f(n, k)
    q = f(n, l) - p
    print(p**3+q**3)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())

def f(n,k):
    return int(n/k)

if k%2:
    print(f(n,k)**3)
else:
    l=k//2
    p=f(n,k)
    q=f(n,l)-p
    print(p**3+q**3)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
a, b = [], []
if(K % 2 == 0):
  for i in range(1,N+1):
    if(i % K == 0):
      a.append(i)
    elif(i % K == K//2):
      b.append(i)
else:
  for i in range(1,N+1):
    if(i % K == 0):
      a.append(i)
print(len(a)**3 + len(b)**3)

Submission status: Accepted

Solution code:
N, K = (int(i) for i in input().split())
if K % 2 == 0:
 n = (2 * N) // K
 ans = ((n+1)//2)**3 + (n//2)**3
else:
 ans = (N // K) ** 3
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

if k%2==1:
  print((n//k)**3)
elif k%2==0:
  print((n//k)**3 + (n//(k//2) - n//k)**3 )

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
 
if K % 2 == 1:
  print(pow(int(N / K), 3))
else:
  even = int(N / K)
  odd = int(N / int(K / 2)) - even
  print(pow(even, 3) + pow(odd, 3))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
if k%2==1:
    print(int((n//k)**3))
else:
    print(int((n//k)**3 + ((n+(k//2))//k)**3))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    N, K = na[0], na[1]

    d, m = int(N / K), N % K
    r = d ** 3
    if K % 2 == 0:
        if K / 2 <= m:
            r += (d + 1) ** 3
        else:
            r *= 2

    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    if K % 2 == 1:
        print((N // K) ** 3)
    else:
        print((N // K) ** 3 + (N // (K // 2) - N // K) ** 3)


main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k % 2 == 1:
    ans = (n // k) ** 3
else:
    x = n // k
    y = n // (k // 2) - x
    ans = x ** 3 + y ** 3
    
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
a,b=0,0
for i in range(1,N+1):
    if i%K==0:
        a+=1
    elif i%K==K/2:
        b+=1
print(a**3+b**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
num = 0

if K % 2 != 0:
    tmp = N // K
    ans = tmp ** 3
else:
    tmp1, tmp2 = 0, 0
    for i in range(1, N+1):
        if i % K == 0:
            tmp1 += 1
        elif i % (K//2) == 0:
            tmp2 += 1
    ans = tmp1 ** 3 + tmp2 ** 3
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
if K==1:
    ans =N**3
elif K%2 ==0:
    a =N//(K//2)
    b =a//2
    a -=b
    ans =a**3+b**3
else:
    a =N//K
    ans =a**3
print(ans)

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))

if K%2 == 1:
    print(int((N//K)**3))
else:
    print(int((N//(K/2)-N//K)**3+(N//K)**3))

Submission status: Accepted

Solution code:
N, K = map(int,input().split())

if K%2 == 1:
    num = N//K
    ans = num**3
else:
    k = K//2
    num = N//k
    even = num//2
    odd = (num+1)//2
    ans = even**3 + odd**3

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, k = LI()

if k % 2 == 1:
    print((n // k) ** 3)
else:
    print((n // k) ** 3 + (((n // (k // 2)) - (n // k)) ** 3))

Submission status: Accepted

Solution code:
N,K = (int(i) for i in input().split())

if K%2==1:
    print((N//K)**3)
else:
    print((N//K)**3+((N-K//2)//K+1)**3)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

a = 0
for i in range(1,N+1):
    if i % K == 0:
        a += 1

if K % 2 == 0:
    b = 0
    for i in range(1,N+1):
        if i % K == (K/2):
            b += 1
    print(a**3 + b**3)
else:
    print(a**3)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=(n//k)**3
if k%2==0:
    n+=k//2
    a+=(n//k)**3
print(a)

Submission status: Accepted

Solution code:
S = list(map(int,input().split()))
N = S[0]
K = S[1]
if K % 2 == 1 :
    x = N // K
    answer = x**3
else:
    x = N // K
    y = (N + K//2) // K
    answer = x**3 + y**3
print(answer)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

ans = 0
if k % 2 == 1:
    ans += (n // k) ** 3
else:
    ans += (n // k) ** 3
    ans += ((n // (k // 2)) - (n // k)) ** 3
    
print(ans)

Submission status: Accepted

Solution code:
n, k=map(int, input().split())
if(k%2==1):
  a=(n//k)**3
else:
  a=(n//k)**3+((n+k/2)//k)**3
print(int(a))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
x = n // k
if (k % 2 == 1):
  print(x * x * x)
else:
  y = (n + k // 2) // k
  print(x * x * x + y * y * y)

Submission status: Accepted

Solution code:
N,K = [int(s) for s in input().split()]
temp = 0
if K % 2 == 0 :
  a = int(N//K)
  b = 0
  temp = int(K/2)
  while True:
    if temp > N:
      break
    b += 1
    temp += K
  print(a**3+b**3)
else:
  a = int(N//K)
  print(a**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K % 2 == 0:
	cnt1 = 0
	cnt2 = 0
	for i in range(1, N+1):
		if i % K == 0: cnt1 += 1
		elif i % (K/2) == 0: cnt2 += 1
	print(cnt1**3 + cnt2**3)

else:
	cnt = 0
	for i in range(1, N+1):
		if i % K == 0: cnt += 1
	print(cnt**3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k % 2 == 1:
    ans = (n // k) ** 3
else:
    num = n // k
    num2 = n // (k // 2) - num
    ans = num ** 3 + num2 ** 3
    
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if (K % 2 == 0):
    print((N // K) ** 3 + (((N + K // 2) // K) ** 3))
else:
    print((N // K) ** 3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K % 2 == 0:
    print((N // K) ** 3 + ((N + (K // 2)) // K) ** 3)
else:
    print((N // K) ** 3)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = n // k
b = 0
if k % 2 == 0:
  b = (n - k // 2) // k + 1
print(a**3+b**3)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if k % 2 == 0:
    a=int(n//k)
    b=int(n//(k/2)-a)
    print(a**3 + b**3)
else:
    a=int(n//k)
    print(a**3)

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]

odd_cnt, even_cnt = 0, 0
for i in range(1, n + 1):
    if i % k == 0:
        odd_cnt += 1
if k % 2 == 0:
    for i in range(1, n + 1):
        if i % k == k / 2:
            even_cnt += 1

print(odd_cnt ** 3 + even_cnt ** 3)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
count=0

for a in range(1,n+1):
    modk = (k-a)%k
    if((modk*2)%k == 0):
        nums = math.floor((n-(k-a)%k)/k)-math.ceil((1-(k-a)%k)/k)+1
        count+=(nums*nums)
    
print(count)

Submission status: Accepted

Solution code:
import itertools as it
N,K = [int(i) for i in input().split()]

candidates = []
even = []
odd = []
for i in range(1,N+1) :
	i = int(i)
	if (i % K == 0) :
		# Kの倍数は候補にする
		even.append(i)
		continue
	
	if (K % 2 == 0 and i % (K/2) == 0) :
		# Kが偶数だったらK/2も候補としてよい
		odd.append(i)
		continue

# a,b,cの組み合わせ(Kが奇数のとき)
count = len(even) * len(even) * len(even)

# a,b,cの組み合わせ(Kが偶数のとき)
# すべての要素がK/2で揃っているケース
if (K % 2 == 0) :
	count += (len(odd) * len(odd) * len(odd))

print(count)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    if k % 2 != 0:
        print((n // k) ** 3)
    else:
        q = n // k
        print(q ** 3 + (n // (k // 2) - q) ** 3)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
if K % 2 == 0:
    a = int(N // K)
    b = int(N // (K / 2) - a)
    print(a**3 + b**3)
else:
    a = int(N // K)
    print(a**3)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
sum = 0
for i in range(1,N+1):
    if 2*i%K != 0:continue
    minx = i//K
    maxx = (i + N)//K
    sum += (maxx - minx)**2
print(sum)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

g_count = 0
k_count = 0

for i in range(1, N+1):
    if i % K == 0:
        g_count += 1
    
    elif i % K == K/2:
        k_count += 1

print(g_count**3 + k_count**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

mod = [i for i in range(K, N+1, K)]
ans = len(mod) ** 3

if K % 2 == 0:
    items = [i for i in range(K//2, N+1, K)]
    ans += len(items) ** 3

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
print(sum([1 if v % k == 0 else 0 for v in range(1, n+1)])**3 +
      sum([1 if v % k == k/2 else 0 for v in range(1, n+1)])**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = 0
b = 0
for i in range(1,n+1):
    if i%k == 0:
        a += 1
    elif i%k == k/2:
        b += 1

print(a**3+b**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
if k % 2 ==1:
    a = n // k 
    print(a ** 3)
else:
    a = n // k
    if (a * k + k // 2) > n:
        print(2 * (a ** 3))
    else:
        print((a + 1) ** 3 + a ** 3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k % 2 != 0:
    ans = (n // k) ** 3
else:
    a = (n // k)
    b = (n // (k // 2) - a)
    ans = a ** 3 + b ** 3
    
print(ans)

Submission status: Accepted

Solution code:
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)
 

def f(b,n):
	if n < b:
		return n
	return f(b, n//b) + n%b
 
N,K = map(int,input().split())

if(K%2==0):
    cnt1=0
    cnt2=0
    for a in range(1,N+1):
        if(a%K==0):
            cnt1+=1
        elif(a%K==K/2):
            cnt2+=1

    print(cnt1**3+cnt2**3)

else:
    cnt=0
    for a in range(1,N+1):
        if(a%K==0):
            cnt+=1
    print(cnt**3)

Submission status: Accepted

Solution code:
N,K = list(map(int, input().split()))

c1 = N // K

cnt = c1
if c1 >= 2:
  cnt += c1 * (c1 - 1) * 3
  if c1 >= 3:
    cnt += c1 * (c1 - 1) * (c1 - 2)

if K % 2 == 0:
  c2 = (N + K // 2) // K
  cnt += c2
  if c2 >= 2:
    cnt += c2 * (c2 - 1) * 3
    if c2 >= 3:
      cnt += c2 * (c2 - 1) * (c2 - 2)
    
print(cnt)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k % 2 != 0:
    x1 = n // k
    print(x1 ** 3)
else:
    x1 = n // k
    x2 = n // (k // 2)
    print(x1 ** 3 + (x2 - x1) ** 3)

Submission status: Accepted

Solution code:
from itertools import product

N, K = map(int, input().split(" "))

"""
i%K == 0 ならその数同士で条件に合う数列を作れる
i%K == K//2 ならその数同士で条件に合う数列を作れる(Kが偶数の場合)
これらは条件によって導ける
"""

count = (N//K)**3
if K%2 == 0:
	count += (N//K + (N%K >= K//2))**3
print(count)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
result = 0
if k % 2 == 0:
    result = ((n + k // 2) // k) ** 3
print(result + (n // k) ** 3)

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
size=math.floor(n/k)
cnt=size*(size-1)*(size-2)+size*(size-1)*3+size
if k%2==0:
    size=math.floor(2*n/k)-size
    cnt+=size*(size-1)*(size-2)+size*(size-1)*3+size

print(cnt)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K % 2 == 0:
    num = N // K
    num2 = N // (K // 2) - num
    ans = num ** 3 + num2 ** 3
    
else:
    num3 = N // K
    ans = num3 ** 3

print(ans)

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))
if K % 2 == 0:
    num = N//K
    num2 = N//(K//2) - num
    print(num**3+num2**3)
else:
    num = N//K
    print(num**3)

Submission status: Accepted

Solution code:
n,k=[int(i) for i in input().split()]
ans=int(n/k)**3+int((n+k/2)/k)**3 if k%2==0 else int(n/k)**3
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

a = []

for i in range(1, n + 1):
    if k % 2 != 0:
        if i % k == 0:
            a.append(i)
    if k % 2 == 0:
        if i % int(k/2) == 0:
            a.append(i)

e = []
f = []
if k % 2 == 0:
    for j in range(len(a)):
        if a[j] % 2 != 0:
            e.append(a[j])
        if a[j] % 2 == 0:
            f.append(a[j])

if k % 2 != 0:
    print(len(a)**3)

if k % 2 == 0:
    if len(a) % 2 != 0:
        print(int(((len(a) + 1)/2) ** 3 + ((len(a) - 1)/2) ** 3))
    else:
        print(int((len(a)/2) ** 3 + (len(a)/2) ** 3))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K % 2 != 0:
    t = N // K
    ans = t ** 3
else:
    t = N // K
    s = (N + K // 2) // K
    ans = t ** 3 + s ** 3
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    even = True if K % 2 == 0 else False
    if even:
        a1 = N//K
        a2 = N//(K//2) - a1
        print(a1**3 + a2**3)
    else:
        print((N//K) ** 3)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product

n, k = map(int, input().split())

zero = n // k
c = zero * zero * zero

if k % 2 == 0:
    half = k // 2
    d = 0
    for i in range(1, n+1):
        if i % k == half:
            d += 1
    c += (d * d * d)

print(c)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()

kk = 0
k2 = 0

for i in range(1,n+1):
    if i%k == 0:
        kk += 1
    elif i%(k/2) == 0:
        k2 += 1
        
print(kk**3 + k2**3)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

ans = (N//K)**3
if K%2 == 0:
    N += K//2
    ans += (N//K)**3
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    
    l = []
    l.append(n//k)

    if k % 2 == 0:
        l.append((n+k//2)//k)

    ans = 0
    for i in l:
        ans += i**3

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
if k%2==1:
    ans=(n//k)**3
else:
    for i in range(1,k+1):
        ans=(n//k)**3 + ((n+k//2)//k)**3
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

n_1 = N//K
if K%2 == 0:
    if N%K < K/2:
        n = (N//K)
    else:
        n = (N//K) +1
    count = n_1 + n_1*(n_1-1)*3 + n_1*(n_1-1)*(n_1-2)
else:
    n = N//K
    count = 0
count += n + n*(n-1)*3 + n*(n-1)*(n-2)

print(count)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
o=n//k
p=0
if (k%2==0): p=(n+(k//2))//k
print(o**3+p**3)

Submission status: Accepted

Solution code:
N, K = [int(_) for _ in input().split()]
count = (N // K) ** 3
if K % 2 == 0:
    count += ((N + (K // 2)) // K) ** 3
print(count)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
a, b = 0, 0
for i in range(1,n+1):
  if i % k == 0:
    a += 1
for i in range(1, n+1):
  if i % k == k // 2:
    b += 1
if k % 2 == 0:
  print(a**3 + b**3)
else:
  print(a**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
cnt = 0

candidates = [i for i in range(K, N + 1, K)]
size = len(candidates)
cnt += size ** 3

if K % 2 == 0:
    for_even_k = [i for i in range(K // 2, N + 1, K)]
    size_for_even = len(for_even_k)
    cnt += size_for_even ** 3

print(cnt)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

if k % 2 != 0:
	dev = n // k
	ans = dev ** 3
else:
	dev = n // k 
	if n % k >= k/2:
		ans = dev**3 + (dev + 1)**3
	else:
		ans = 2 * (dev**3)

print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
if k%2==1:
    a=n//k
    print(a**3)
else:
    a=n//k
    b=n//(k//2)-a
    print(a**3+b**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if K % 2:
    m = N // K
    print(m ** 3)
else:
    m = (2 * N) // K
    print(((m + 1) // 2) ** 3 + (m // 2) ** 3)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())

    m = defaultdict(int)
    for i in range(1, N + 1):
        m[i % K] += 1

    ans = 0
    for a in range(1, N + 1):
        if (a + a) % K == 0:
            ans += m[a % K] ** 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ans = (N//K)**3
if K%2==0:
    ans += ((N+K//2)//K)**3
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())

ans=(n//k)**3
if(k%2==0):
    ans+=((n+k//2)//k)**3
print(ans)

Submission status: Accepted

Solution code:
(n, k) = map(int, input().split())
a = n // k
ans = a ** 3

if k % 2 == 0:
    b = n // (k // 2)
    ans += (b - a) ** 3
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
num1 = n / k
num2 = 0
if k % 2 == 0:
    if n % k >= k / 2:
        num2 = num1 + 1
    else:
        num2 = num1
print num1**3+num2**3

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
result = (N//K)**3
if K % 2 == 0:
    if N-K*(N//K) < K/2:
        result += (N//K)**3
    else:
        result += ((N//K)+1)**3

print(result)

Submission status: Accepted

Solution code:
N, K = map(int, input().split(' '))
a=N//K
if K%2==0:
    b=((N-K//2)//K)+1
    print((a**3) +(b**3))
else:
    print(a**3)

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())

c = 0
d = 0
for i in range(1, N + 1):
	if i % K == 0:
		c += 1
	elif K % 2 == 0 and i % K == K / 2:
		d += 1
print c ** 3 + d ** 3

Submission status: Accepted

Solution code:
def m():
    n, k = map(int, input().split())
    half = k // 2
    odd = 0
    even = 0
    even_half = 0
    for i in range(1, n+1):
        if k % 2 == 0:
            if i % k == 0:
                even += 1
            if i % k == half:
                even_half += 1
        else:
            if i % k == 0:
                odd += 1
    ans = max(odd ** 3, even ** 3 + even_half ** 3)
    return ans
print(m())

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
num = (n // k) ** 3
if k % 2 == 0:
    if n - ((n // k) * k) < k // 2:
        print(num * 2)
    else:
        print(num + ((n // k + 1) ** 3))
else:
    print(num)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

tmp = N // K

if K % 2 == 0:
    a = N // (K // 2) - tmp
    print(tmp ** 3 + a ** 3)
else:
    print(tmp ** 3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split( ))
ans = (N//K)**3
if K % 2 == 0:
	c = -(N//K)
	for i in range(N):
		if (i + 1) % (K // 2) == 0:
			c += 1
	ans += c**3
print(ans)

Submission status: Accepted

Solution code:
import math

N,K=map(int,input().split())

x=N//K
if K%2:
    print(x**3)
else:
    y=math.floor(N/K+1/2)
    print(x**3+y**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

if k%2 ==1:
  print(int(n//k)**3)
else:
  print(int((n//k)**3 + ((n+(k/2))//k)**3))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# mod Kをうまく使ってaを全検索

N,K = map(int, input().split())

num = [0] * K
# 元のNまでの数がmod Kの世界で何になるかを集計
for i in range(1,N+1):
    num[i%K] += 1

ans = 0
# a mod Kを決め打ちしてb mod Kとc mod Kを出す
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    # つじつまが合ってるか確認
    if (b + c) % K == 0:
        # 予め集計してあるmod Kでの数を合計させる
        ans += num[a] * num[b] * num[c]
print(ans)

Submission status: Accepted

Solution code:
import itertools
n,k=map(int,input().split())
aa=k/2
a=[]
b=[]
if k%2==0:
    for i in range(1,n+1):
        if i%k==0:
            a.append(i)
        elif i%k==aa:
            b.append(i)
else:
    for i in range(1,n+1):
        if i%k==0:
            a.append(i)
tot=len(set(a))**3+len(set(b))**3
print(tot)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = (n // k)**3
if k % 2 == 0:
    ans += (n // (k // 2) - n // k)**3
print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd


def main():
    n, k = map(int, input().split())

    ans = 0

    if k % 2 == 1:
        ans = (n // k)**3
    else:
        ans = (n // k)**3 + ((n + k // 2) // k)**3
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

N, K = map(int, input().split())

count = 0

count = int(N / K) ** 3

if K % 2 == 0:
    c = int((N - (K / 2)) / K + 1)
    count += c**3

print(count)

sys.exit(0)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if(K%2 != 0):
    odd = (N // K)**3 # 選び方はa,b,cそれぞれN//K個ある
    print(int(odd))
else:
    c= N//(K/2)
    d= N//K
    e=c-d
    print(int(e**3 + d**3))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
ans2=0
for i in range(1,n+1):
    if(i%k==0):ans+=1
    if(i%k==k//2 and k%2==0):ans2+=1
print(ans**3+ans2**3)

Submission status: Accepted

Solution code:
n, k = [int(_) for _ in input().split()]
ans = 0
for i in range(0, min(k, n+1)):
    if (2 * i) % k == 0:
        if i == 0:
            m = n // k
            ans += m + 3*m*(m-1) + m*(m-1)*(m-2)
        else:
            m = ((n-i) // k) + 1
            ans += m + 3*m*(m-1) + m*(m-1)*(m-2)
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
print((n//k)**3+(k+1)%2*((n-k//2)//k+1)**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
ans2 = 0
for i in range(1,n+1):
    if i % k == 0:
        ans += 1
    if i % k == k//2 and k%2 == 0:
        ans2 += 1
print(ans**3 + ans2**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
s = (n//k)**3
if k%2 == 0:
  l = k//2
  s += ((n//l+1)//2)**3
print(s)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())

if k%2==1:
    c=int(n//k)
    print(c*c*c) 
else:
    c=int(n//(k/2))
    d=int(n//k)
    e=c-d
    print(e*e*e+d*d*d)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())

if K%2==1:
	print(int((N//K)**3))
else:
	print(int( (N//K)**3 + ((N+(K/2))//K)**3 ))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

def counter(N, K):
    if K % 2 == 1:
        return (int(N/K))**3
    if K % 2 == 0:
        A = (int(N/K))**3
        B = (int(2*N/K)-int(N/K))**3
        return A+B
            
print(counter(N,K))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

p1 = N // K
p2 = (N + K // 2) // K

if K % 2 == 1:
    print(p1 ** 3)
else:
    print(p1 ** 3 + p2 ** 3)

Submission status: Accepted

Solution code:
a = input()
N = int(a.split(" ")[0])
K = int(a.split(" ")[1])
count = 0
if K%2 == 1:
    count = int(N/K)**3
else:
    count = int(N/K)*int(N/K)*int(N/K)*2
    if int(N/K)*K + K/2 <= N:
        count = int(count/2) + (int(N/K)+1)**3
print(count)

Submission status: Accepted

Solution code:
n, k = [int(v) for v in input().split()]

cnt = n // k
ans = cnt * cnt * cnt
if k % 2 == 0:
    k //= 2
    cnt = n // k - cnt
    ans += cnt * cnt * cnt

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
if K%2==1:
    n=N//K
    print(n**3)
else:
    n=N//K
    m=0
    for i in range(1,N+1):
        if i%K==K//2:
            m+=1
    print(n**3+m**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

"""
まずはn+nまでの数の中で、kの倍数が何個あるのか？何か？を調べる
足してそれになる組み合わせを調べる（このとき、２つの数字は同じor 違うときがある）
"""
"""
kが奇数の時,abcは全てkの倍数出ないと無理
kが奇数の時、abcはk/2の倍数でないと無理
"""

if k%2 == 1:
	ans = (n//k)**3
else:
	ans = (n//k)**3 + ((n + k//2) //k) ** 3

print(ans)