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:
# -*- coding: utf-8 -*-
def main():
    N, K = map(int, input().split())
    if K%2==0:
        A = N//K
        B = N//(K//2)
        print(A**3+(B-A)**3)
    else:
        A = N//K
        print(A**3)
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())
count_0 = 0
count_2 = 0

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
M1 = []
M2 = []
M1 = [a for a in range(N+1) if a % K == 0]
M1.pop(0)
if K % 2 == 0:
    M2 = [a for a in range(N+1) if a % K == K//2]
print(len(M1)**3 + len(M2)**3)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
num=[0]*(k+1)
for i in range(1,n+1):
    num[i%k]+=1

for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k:continue
    cnt+=num[a]*num[b]*num[c]
    
print(cnt)

Submission status: Accepted

Solution code:
# 2019/09/10
# かんにんぐ

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

Submission status: Accepted

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

numl = []
numl2 = []

for i in range(1,n+1):
  if (i%k == 0):
    numl.append(i)

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

num = len(numl)
num2 = len(numl2)
ans = num**3 + num2**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 = [int(x) for x in input().split()]
a = n//k
b = 0
if k % 2 == 0:
  b = n//(k//2)-n//k;
print(a**3 + b**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
if K % 2 != 0:
    ans = (N // K) ** 3
else:
    tmp1 = K // 2
    tmp2 = (N // tmp1) - (N // K)
    ans = (N // K) ** 3 + tmp2 ** 3

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

def main():
    N,K = map(int,input().split())
    r1 = 0
    for i in range(1,N+1):
        if i%K == 0:
            r1 += 1
    if K%2 == 1:
        print(r1**3)
    else:
        r2 = 0
        for i in range(1,N+1):
            if i%K == K//2:
                r2 += 1
        print(r1**3+r2**3)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if K % 2 == 0:
    list_abc = []
    list_abc_2 = []
    for i in range(1, N + 1):
        if i % K == 0:
            list_abc.append(i)
        elif i % K == (K / 2):
            list_abc_2.append(i)
    print(len(list_abc) ** 3 + len(list_abc_2) ** 3)


else:
    list_abc = []
    for i in range(1, N + 1):
        if i % K == 0:
            list_abc.append(i)
    print(len(list_abc) ** 3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, 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())

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

Submission status: Accepted

Solution code:
from math import ceil 

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

count = 0
num = n // k
bb = [(i+1)*k for i in range(num) ]
s = len(bb) 
count += s + 3*s*(s-1) + s*(s-1)*(s-2)  

if k % 2 == 0:    
  bb=[]
  tmp = k//2  
  while tmp <= n:
    bb.append(tmp)
    tmp += k      
  s = len(bb)
  count += s + 3*s*(s-1) + s*(s-1)*(s-2)

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

if K%2 == 1:
    M = N//K
    print(M*M*M)
else:
    M = 2*N//K
    if M%2 == 0:
        evenM = M//2
        oddM = M//2
    else:
        evenM = (M-1)//2
        oddM = (M+1)//2
    print(evenM*evenM*evenM + oddM*oddM*oddM)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=[int(s) for s in input().split()]
if K%2==1:
  ###N以下のKの正の倍数を並べれば良い
  a=N//K
  print(a**3)
else:
  ans=0
  ###全てがKの倍数の場合
  a=N//K
  ans+=a**3
  ###全てがK/2の倍数かつKの倍数でない場合
  b=N//(K//2)
  ans+=(b-a)**3
  print(ans)

Submission status: Accepted

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


"""考え方
Kが奇数か否か、1か、で考える。

1.K=1
N**3

2.Kが偶数
「全てN以下のKの倍数」、「全てがx*K/2」のいずれか。

3.Kが奇数
全ての値が、「Kの倍数」でないといけない。
なので、N以下のKの倍数の個数をカウントし、3乗する。
"""

base = int(N//K)**3

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans1 = (n//k)**3
ans2 = 0
if k % 2 == 0:
    if n % k >= k // 2:
        ans2 = (n//k+1)**3
    else:
        ans2 = (n//k)**3
print(ans1+ans2)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc108/tasks/arc102_a
# C - Triangular Relationship
import copy
import itertools
N, K = list(map(int, input().split()))
ab_list = []

# 2 * a = (X + Y - Z) * K
# a = (X + Y - Z) * K / 2
# が成り立つ
# Kが偶数の場合は
# a = T * K または a = T * (1/2)K
# a + b = T * K なので、a, b, cのいずれか１つが a % (1/2)K == 0なら、全てそうである必要がある
# Kが偶数の場合は (1/2)*Kが整数にならないので
# a = T * K

if K % 2 == 0:
    a_list = [x for x in range(1, N + 1) if x % K == 0]
    p = len(a_list) ** 3
    a_list = [x for x in range(1, N + 1) if (x % (0.5 * K)) == 0 and not (x % K == 0)]
    p += len(a_list) ** 3
else:
    a_list = [x for x in range(1, N + 1) if x % K == 0]
    p = len(a_list) ** 3

print(p)

Submission status: Accepted

Solution code:
def solve():
    N, K = map(int, input().split())
    count = 0
    is_k_even = K%2 == 0
    # half_k_mod = []
    half_k_mod = 0
    # k_mod = []
    k_mod = 0
    for i in range(1, N+1):
        if (i % K) == 0:
            # k_mod.append(i)
            k_mod += 1
        elif is_k_even and (i % K) == K//2:
            # half_k_mod.append(i)
            half_k_mod += 1
    
    count = k_mod ** 3 + half_k_mod ** 3
    print(count)
    
solve()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
ct1 = 0
ct2 = 0
for i in range(1, n + 1):
    if i % k == 0:
        ct1 += 1
if k % 2 == 1:
    print(ct1 ** 3)
else:
    for i in range(1, n + 1):
        if i % k == (k // 2):
            ct2 += 1
    print(ct1 ** 3 + ct2 ** 3)

Submission status: Accepted

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

    if K&1:
        count = 0
        for i in range(1, N+1):
            if i%K == 0:
                count += 1
        print(pow(count, 3))
    else:
        count = [0, 0]
        k2 = K//2
        for i in range(1, N+1):
            tmp = i%K
            if tmp == 0:
                count[0] += 1
            elif tmp == k2:
                count[1] += 1
        print(pow(count[0], 3) + pow(count[1], 3))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

# https://atcoder.jp/contests/abc108/submissions/5741604


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

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

Submission status: Accepted

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

Submission status: Accepted

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

if K % 2 == 0:
    ans = (N // K) ** 3 + ((N + K // 2) // K) ** 3
else:
    ans = (N // K) ** 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 + 1) ** 3)
  
else:
  print((n//k) ** 3)

Submission status: Accepted

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

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

Submission status: Accepted

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

mod=[n//k]*k
if n%k!=0:
    for i in range(1, n%k+1):
        mod[i]+=1

ans=0
for a in range(k):
    a_mod=a%k
    if a_mod==0:
        b_mod=0
        c_mod=0
    else:
        b_mod=k-a_mod
        c_mod=k-a_mod
    if (b_mod+c_mod)%k==0:
        ans+=mod[a_mod]*mod[b_mod]*mod[c_mod]
print(ans)

Submission status: Accepted

Solution code:

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


num = N // K


if K % 2 == 0:

    numH = N // (K // 2) - num

else:

    numH = 0

print (num ** 3 + numH ** 3)

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,K = II()

ans = 0

for i in range(1,N+1):
    x = i%K
    if -2*x %K ==0:
        s = -x%K
        if s==0: s=K
        ans += ((N-s)//K + 1)**2

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(1, n+1):
    if i % k == 0:
        cnt += 1

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

res = cnt ** 3 + cnt_2 ** 3

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#解説
N, K = [int(nk) for nk in input().split()]

ans = 0
for a in range(1, N+1):
  bK_mod = K - a%K
  cK_mod = K - a%K
  bcK_mod = bK_mod + cK_mod
  if bcK_mod % K == 0:
    howmany_b = (N - bK_mod)//K + 1
    howmany_c = (N - cK_mod)//K + 1
    ans += (howmany_b * howmany_c)

print(ans)

Submission status: Accepted

Solution code:
N, K = [int(nk) for nk in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

    x = 0
    y = 0
    for i in range(1, N + 1):
        if i % K == 0:
            x += 1
        elif i % K == int(K / 2):
            y += 1

    if K % 2 == 0:
        print(x ** 3 + y ** 3)
    else:
        print(x ** 3)


main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# Kの倍数を全網羅する方針？
# 最大長は3N
# 2, 4, 6, 8
if __name__ == "__main__":
    N, K = map(int, sys.stdin.readline().split())
    if K % 2 == 0:
        a = N // K
        # b = (N + (K // 2)) // K
        b = N // (K // 2) - a
        print(a ** 3 + b ** 3)
    else:
        a = N // K
        print(a ** 3)

Submission status: Accepted

Solution code:
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# Kの倍数を全網羅する方針？
# 最大長は3N
# 2, 4, 6, 8
if __name__ == "__main__":
    N, K = map(int, sys.stdin.readline().split())
    if K % 2 == 0:
        a = N // K
        b = (N + (K // 2)) // K
        print(a ** 3 + b ** 3)
    else:
        a = N // K
        print(a ** 3)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

if K%2 == 0:  # K が偶数
	print((N//K)**3+((N//(K//2)-N//K))**3)
else:  # K が奇数
	print((N//K)**3)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math

def solve(N: int, K: int):

    ans = int(N/K) ** 3

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

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
words = lambda t : list(map(t, input().split()))
n,k = words(int)

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

Submission status: Accepted

Solution code:
import math

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

ans = int(math.pow(int(n/k),3))

if(k % 2 == 0):
  m = int( (n+int(k/2))/ k )
  ans += int(math.pow(m,3))

print(ans)

Submission status: Accepted

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

half = 0
zero = 0

if K%2==0:
	for i in range(1,N+1):
		if i%K==K/2:
			half+=1
		if i%K==0:
			zero+=1

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

print(half**3+zero**3)

Submission status: Accepted

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

n=N//K
ans+=n
if n>=2:
    ans+=n*(n-1)*3
    if n>=3:
        ans+=n*(n-1)*(n-2)
#print(ans)#1
if K%2==1:
    #n=N//K
    #ans+=nk
    #if nk>=2:
    #    ans+=nk*(nk-1)*3/2
    #    if nk>=3:
    #        ans+=nk*(nk-1)*(nk-2)
    #print(ans)
    print(int(ans))
else:
    #n=N//(K/2)
    #n=(N-K/2)//K
    n=(N+K/2)//K
    #print("n",n)#2
    ans+=n
#if n>=2:
#    ans+=n*(n-1)*3/2
#    if n>=3:
#        ans+=n*(n-1)*(n-2)
#print(int(ans))
    if n>=2:
        #ans+=n*(n-1)*3/2
        ans+=n*(n-1)*3
        if n>=3:
            ans+=n*(n-1)*(n-2)
    print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if k%2:
# n以下のkの倍数
    print((n // k)**3)
else:
    mid_num = (n // (k // 2)) - (n // k)
    print(mid_num ** 3 + (n // k) ** 3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
mod0 = []
mod2 = []
for i in range(1, n + 1):
    if i % k == 0:
        mod0.append(i)
    elif k % 2 == 0 and i % k == k // 2:
        mod2.append(i)
print(len(mod0) * len(mod0) * len(mod0) + len(mod2) * len(mod2) * len(mod2))

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = string_to_int(inputs[0])
    count_a = 0
    count_b = 0
    for i in range(1, N+1):
        if i % K == 0:
            count_a += 1
        if i % K == K/2:
            count_b += 1

    count = count_a ** 3
    if K % 2 == 0:
        count += count_b ** 3
    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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(int(ans))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0

ans += (N // K)**3

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter

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

if __name__ == '__main__':
	main()

Submission status: Accepted

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

if K%2 != 0:
  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==1:
    x=N//K
    print(x**3)
else:
    x=N//K
    y=N//(K//2)-x
    print(x**3+y**3)

Submission status: Accepted

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


def f(x): return x + x * (x - 1) * 3 + x * (x - 1) * (x - 2)


if K % 2 == 0:
    a = N // K
    b = N // (K // 2) - a
    ans = f(a) + f(b)
else:
    ans = f((2 * N) // (K * 2))
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
if k % 2 == 1:
  x = n // k
  print( x ** 3 )
else:
  x = n // k
  y = n // (k//2) - x
  print( x ** 3 + y ** 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:
from math import ceil

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

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

Submission status: Accepted

Solution code:

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n,k=getints()

x = n // k

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

n,k = map(int,input().split())
ans = 0
if k%2 != 0:
    ans = (n//k)**3
else:
    d = k//2
    ans = (n//k)**3 + ((n-d)//k + 1)**3
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

if k%2 == 0:
    temp = 0
    temp = 0
    for i in range(1,n+1):
        if i%k == 0:
            temp += 1
    ans = temp**3
    temp = 0
    for i in range(1,n+1):
        if i%k == k//2:
            temp += 1
    ans += temp**3
    print(ans)
else:
    temp = 0
    for i in range(1,n+1):
        if i%k == 0:
            temp += 1
    print(temp**3)

Submission status: Accepted

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

khalf = 0

if k%2 == 0:
    khalf = n // (k*0.5)

if khalf%2 == 0:
    khalf = khalf // 2
else:
    khalf = khalf // 2 + 1

kraw = n // k

print(int(khalf**3+kraw**3))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
X = [2*i//K for i in range(1,N+1) if 2*i%K == 0]
count1 = 0
count2 = 0
for x in X:
    if x%2 == 0:
        count1 += 1
    else:
        count2 += 1
print(count1**3 + count2**3)

Submission status: Accepted

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

    if k % 2 == 1:
        print((n // k) ** 3)
        return

    k2 = k // 2
    even = n // k
    odd = (n - k2) // k + 1 if n >= k2 else 0
    print(even ** 3 + odd ** 3)


main()

Submission status: Accepted

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

if k%2 == 1:
  #a,b,cは全てkの倍数
  #n以下のkの倍数の個数
  s = n // k
  print(s ** 3)
  
else:
  #a,b,cは全てkの倍数 or kで割ってk/2余る数
  #n以下のkの倍数の個数
  s = n // k
  #kで割ってk/2余る数 = k/2の倍数の個数　-  s
  l = n // (k // 2) - s
  ans = s ** 3 + l **3
  print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
if K == 1:
    print(N*N*N)
else:
    if K%2==0:
        b = N // (K//2)
        if b % 2 == 0:
            b0 = b//2
            print(2 * (b0*b0*b0))
        else:
            b1 = (b+1)//2
            b2 = (b-1)//2
            print(b1*b1*b1+b2*b2*b2)
    else:
        c = N//K
        print(c*c*c)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, K: int):
    if K % 2 == 0:
        d = N // K
        dd = (N + K // 2) // K
        print(d ** 3 + dd ** 3)
    else:
        d = N // K
        print(d ** 3)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

nk = N//K
ans = nk*nk*nk

if(K%2==0):
  nk2 = N//(K//2) - nk
  ans += nk2*nk2*nk2

print(ans)

Submission status: Accepted

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

# a+b, b+c, c+a が全てKの倍数になるのは、
# 1. (a%K, b%K, c%K) = (0, 0, 0)
# 2. (a%K, b%K, c%K) = (K/2, K/2, K/2) の時だけ
# このうち、2の条件はKが奇数の時成立しないので、Kの偶奇で分けてそれぞれの条件を考える

# 1の条件: a, b, c は N以下のKの倍数 なので、その個数の3乗
cnt = int(N / K) ** 3

# 2の条件: N以下のKで割ってK/2余る数 = N+K/2以下のKの倍数 の個数の3乗
if K % 2 == 0:
    cnt += int((N + K / 2) / K) ** 3

print(cnt)

Submission status: Accepted

Solution code:
import collections

n, k = map(int, input().split())
d = collections.Counter(x % k for x in range(1, n + 1))
ans = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k == 0:
        ans += d[a] * d[b] * d[c]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

mod0 = 0
modk2 = 0
for i in range(1,n+1):
    if i%k == 0:
        mod0 += 1
    if k%2 == 0:
        if i%k == k//2:
            modk2 += 1
res = 0
if k % 2 != 0:
    res = mod0**3
else:
    res += mod0**3
    res += modk2**3
print(res)

Submission status: Accepted

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

if K%2 == 1:
    count = 0
    for i in range(1,N+1):
        if i%K == 0:
            count += 1
    ans = count**3
else:
    count = 0
    c = 0
    for j in range(1,N+1):
        if j%K == 0:
            count += 1
        elif j%(K/2) == 0:
            c += 1
    ans = count**3 + c**3

print(ans)

Submission status: Accepted

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

m = N // K

if K % 2 == 0:
    if 2*(N%K)>=K:
        ans = m**3 + (m+1)**3
    else:
        ans = 2 * m**3
else:
    ans = m**3

print(ans)

Submission status: Accepted

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

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)