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())
list0, list1, list2 = [],[],[]
j = 1

if K % 2 == 1:
  i = K * 1
  while i <= N:
    list0.append(int(i))
    j += 1
    i = K * j
  ans = len(list0) ** 3
else:
  i = K / 2
  while i <= N:
    if j % 2 == 0:
      list1.append(int(i))
    if j % 2 == 1:
      list2.append(int(i))
    j += 1
    i = K * j / 2
  ans = len(list1) ** 3 + len(list2) ** 3
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
# N以下の正の整数
# Kの倍数
# a+b, b+c, c+a a < b < c
# a, b, c すべてのmodが 0 or K/2 (n=1,2,3,...) となる必要がある

# Kで割った余りが0 or K/2(偶数の時)以外ムリでは？
# Kで割った余りが0の時
ans = 0
cnt = N//K
ans += cnt ** 3
# Kで割った余りがK/2の時(偶数のみ)
if K % 2 == 0:
    n = 0
    cnt = 0
    while (n + 1/2) * K <= N:
        cnt += 1
        n += 1
    ans += cnt ** 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())

if K%2 == 0: #Kが偶数の時
    a = N//K
    b = (N+K//2)//K
    ans = a ** 3 + b ** 3
else: #Kが奇数の時3
    a = N//K
    ans = a ** 3

print (ans)

Submission status: Accepted

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

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:
a,b=map(int,input().split())
c=a//b
print((c**3)+((a-b//2)//b+1)**3*(1-b%2))

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

if K%2 == 1:
  cand = N // K
  ans = cand\
      + cand * (cand-1) * 3\
      + cand * (cand-1) * (cand-2)
  print(int(ans))
else:
  cand_mod0 = N // K
  ans_mod0 = cand_mod0\
           + cand_mod0 * (cand_mod0-1) * 3\
           + cand_mod0 * (cand_mod0-1) * (cand_mod0-2)
  cand_modhalf = N // K if N % K < K / 2 else (N // K) + 1
  ans_modhalf = cand_modhalf\
           + cand_modhalf * (cand_modhalf-1) * 3\
           + cand_modhalf * (cand_modhalf-1) * (cand_modhalf-2)
  print(int(ans_mod0 + ans_modhalf))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

    print(count1 ** 3 + count2 ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

def count(a):
  bias = a % k
  if (bias + a) % k:
    return 0
  num = (n - bias) // k 
  if bias > 0:
    num += 1
  return num ** 2

a = 1
res = 0

while(a <= n):
  res += count(a)
  a += 1

print(res)

Submission status: Accepted

Solution code:
N, K = map(int, (input().split()))
ans_zero = set()
ans_notzero = set()
for i in range(1, N+1):
    if i % K == 0:
        ans_zero.add(i)

    elif i % K == K / 2:
        ans_notzero.add(i)

print(len(ans_zero) ** 3 + len(ans_notzero) ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

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

    # K|a+b K|b+c K|c+a
    # K|2a  K|2b  K|2c

    # Kが奇数のとき、 K|a も K|b も K|c も、Kの倍数
    # Kが偶数のとき、 K/2|a  K/2|b  K/2|c
    if K%2 != 0:
        # Kが奇数のとき、aがKで割り切れる数は、
        kinds = (N//K)  # kinds通りある
        # 同様に、b, cも kinds通りある。
        # よって、答えはa, b, cの組み合わせなので
        print(kinds**3)
        return
    K //= 2
    m = N // K
    ans = (m//2) ** 3 + (m - m//2) ** 3
    print(ans)
    return           


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:


import math
N,K = list(map(int,input().split(" ")))
nums = (K) * [0]
for i in range(1,N+1):
    nums[i%K] += 1
ans = 0
for a in range(K):
    b = (K-a) % K 
    c = (K-a) % K
    if (2 * K - 2 * a) % K != 0:
        continue
    # print("a,b,c = ",a,b,c)
    # print("nums:",nums)
    ans += nums[a] * nums[b] * nums[c]

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
if k%2 == 0:
    #k mod halfの個数は
    mod1 = (n+(k//2))//k
    #k mod0の個数は
    mod2 = n//k
    
    ans += mod1**3 + mod2**3
    
else:
    #kmod0の個数は
    modk = n//k
    
    ans += modk**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = (n // k) ** 3

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


print(int(ans))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from sys import exit, stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
num = [0]*K
for i in range(1, N+1):
    num[i%K]+=1
res = 0
for a in range(K):
    b = (K-a) % K
    c = (K-a) % K
    if ((b+c) % K != 0):
        continue
    res += num[a] * num[b] * num[c]
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

if K==1:
    print(N**3)
    exit()
# if K==2:
#     print( ((N+1)//2)**3 +((N//2)**3))
#     exit()
if not K%2 == 0:
    print((N//K)**3)
    exit()

# print(N/K)
print((N//K)**3 +(int(N/K + 1/2)**3))

Submission status: Accepted

Solution code:
import math
import sys


def parse(file):
    n, k = map(int, file.readline().split())
    return n, k


def main(n, k):
    if k % 2 == 1:
        return math.floor(n / k) ** 3
    else:
        return math.floor(n / k) ** 3 + math.floor((n + k/2) / k) ** 3


if __name__ == '__main__':
    print(main(*parse(sys.stdin)))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if k % 2 != 0:
  print((n // k) ** 3)
else:
  if n % k >= k // 2:
    print((n // k) ** 3 + (n // k + 1) ** 3)
  else:
    print((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)
else:
    modKp2 = 0
    for i in range(1, N+1):
        if i%K==K//2:
            modKp2+=1
    print((N//K)**3+modKp2**3)

Submission status: Accepted

Solution code:
N,K = map(int,input().split(" "))
sum = (N//K) ** 3

if K % 2 == 0:
    k = K // 2
    sum += ((N+k)//K) * (((N+K-k)//K)**2)

print(sum)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
N = N+1
setK = set()
setK2 = set()
for i in range(1,N):
    if i%K == 0:
        setK.add(i)
    elif K%2 == 0 and i%K == K/2:
        setK2.add(i)
        
ans = (len(setK)) ** 3 + (len(setK2)) ** 3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
 
#奇数の時
if K%2:
    a = N//K
    print(a**3)
#偶数の時
else:
    #Nまででa,b,cそれぞれがKで割り切れる数(割り切れる数同士の和も割り切れる)
    a = N//K
    #あまりがk/2(和がkの倍数になる場合)
    b = (N+K//2)//K
    print(a**3 + b**3)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

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

	ans = 0
	ans2 = 0
	for i in range(1, N+1):
		if i % K == 0:
			#print(i)
			ans += 1
		elif K % 2 == 0 and i % K == K/2:
			#print(i)
			ans2 += 1
	
	print(ans*ans*ans + ans2*ans2*ans2)

	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

        base = n // (k // 2)
        if base % 2 == 0:
            base = base // 2
        else:
            base = (base + 1) // 2

        ans += base ** 3

        print(ans)

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
    a2 = N//(K//2) -a
    print(a**3 +a2**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
num0 = 0
num1 = 0
if(K%2 == 0):
    num1 = int(N/K)
    num0 = int(N/K*2)-num1
else:
    num1 = int(N/K)
print(num1**3+num0**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

hk = 0

ans = (n//k)**3

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K = li_input()

    x,y = 0, 0

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

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





main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])

    return result


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

    # N以下のKの倍数の個数
    ans = (N//K)**3
    # print(ans)

    if K & 1 == 0:
        # 偶数ならK//2の倍数であってKの倍数でないものの組み合わせも必要
        ans += (N//(K//2) - N//K)**3

    print(ans)
    return


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 = map(int, input().split())

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

Submission status: Accepted

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

print(result)

Submission status: Accepted

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

total = 0
total += (N // K)**3

if K % 2 == 0:
    K //= 2
    n = N // K
    n = n // 2 + n % 2
    total += n**3

print(total)

Submission status: Accepted

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

#(ex)K=4
#a%4=1,b%4=2はありえない->なぜならc%4=3かつc%4=2となることはないから
#以上よりa%K = b%K = c%K -> 2つ合わせたらKの倍数より
#mod K で(a,b,c) = (K/2,K/2,K,2) or (a,b,c) = (0,0,0)の2パターンのみ
#1 ~ Nのうち
#1: mod K:K/2 となるものがp個 -> 組み合わせ:p*p*p = p^3通り
#2: mod K:0 となるものがq個 -> 組み合わせ:q*q*q = q^3通り
#ans = p^3 + q^3
p,q = 0,0
if(K%2 == 0):
 for i in range(1,N+1):
  if(i%K == K//2): p += 1
  elif(i%K == 0): q += 1
else:
 for i in range(1,N+1):
  if(i%K == 0): q += 1
ans = p**3 + q**3
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

mult = N//K
if K % 2 == 1:
    halfmult = 0
elif N % K < K//2:
    halfmult = mult
else:
    halfmult = mult + 1

print(mult**3 + halfmult**3)

Submission status: Accepted

Solution code:
N,K=[int(x) for x in input().split()]
if K%2:
  mod0=N//K
  print(mod0**3)
else:
  mod0,MODN=divmod(N,K)
  if MODN>=K//2:
    print(mod0**3+(mod0+1)**3)
  else:
    print((mod0**3)*2)

Submission status: Accepted

Solution code:
""" AtCoder """

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP
n,k = map(int,input().split())
ans = 0
if k % 2 ==0:
    p = Decimal(n/k).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
    ans = p**3 +(n//k)**3
else:
    ans = (n // k)**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,math

A = [int(i) for i in input().split(' ')]
N,K = A[0], A[1]

ans = math.floor(N/K) ** 3

if (K%2 == 1):
  print(ans)
  sys.exit()

res = 0
half = math.floor(K/2)
cnt = (math.floor((N - half)/K)+1)** 3
print(cnt+ans)

Submission status: Accepted

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

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

if K % 2 != 0:
    print(res1**3)
    exit()

res2 = 0

for i in range(1,N+1):
    if i % K == int(K/2):
        res2 += 1


print(res1**3+res2**3)

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

Submission status: Accepted

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

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+1)**3 if n%k>=k//2 else (n//k)**3))

Submission status: Accepted

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

ans = 0
a = n//k
if k%2==1:
    print(a**3)
else:
    p = k/2
    count = 0
    while p<=n:
        count+=1
        p += k

    print(a**3 + count**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
N, K = map(int, stdin.readline().split())
pos_a = []
for i in range(1, K+1):
    if (-2*i) % K == 0:
        pos_a.append(i)
ans = 0
for a in pos_a:
    tmp = (-a) % K
    count = len(range(a, N+1, K))
    ans += count * len([i for i in range(tmp, N+1, K) if i > 0])**2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = 0
d = 0

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

if K%2==0:
	print(c*c*c+d*d*d)
else:
	print(c*c*c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def kumiawase(num):
    return num + 3*num*(num-1) + num*(num-1)*(num-2)

n, k = list(map(int, input().split()))
if k%2 == 1:
    ans = kumiawase(n//k)
else:
    m = k//2
    ans = kumiawase(n//k) + kumiawase(n//m - n//k)
print(ans)

Submission status: Accepted

Solution code:
def kumiawase(num):
    return num + 3*num*(num-1) + num*(num-1)*(num-2)

n, k = list(map(int, input().split()))
if k%2 == 1:
    ans = kumiawase(n//k)
else:
    m = k//2
    if m % k == 0:
        ans = kumiawase(n//m)
    else:
        ans = kumiawase(n//k) + kumiawase(n//m - n//k)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

#以下,Kを法とする
mod_0_num=N//K
mod_K_num=0
if(K%2==0):
    mod_K_num=(N-K//2)//K +1

print(mod_0_num**3+mod_K_num**3)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
cnt=N // K
ch=N % K

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

Submission status: Accepted

Solution code:
a,b = map(int,input().split())

if b%2 != 0:
  print(pow(a//b,3))
else:
  print(pow(a//b,3)+pow(((a+b//2)//b),3))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    n,k = [int(i) for i in input().split()]
    group = defaultdict(list)
    ans = 0
    for i in range(1,n+1):
        group[i%k].append(i)
    ans += len(group[0])**3
    if k%2==0:
        ans += len(group[k//2])**3
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 0

if K % 2 == 0:
  count = 0
  n = K//2
  while n <= N:
    count += 1
    n += K
  res += count**3

count = 0
n = K
while n <= N:
  count += 1
  n += K

res += count**3
print(res)

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:
n,k = map(int, input().split())
ans = int((n//k) ** 3)
if k%2 == 0:
    ans += int(((n-k/2)//k + 1) ** 3)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0

if k % 2 == 0:
  k_2 = k // 2
else:
  k_2 = k

for a in range(k_2, n+1, k_2):
  cnt += len(range(k-(a%k), n+1, k)) ** 2
        
print(cnt)

Submission status: Accepted

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

l1 = list(range(K, N + 1, K))
l2 = list(range(K//2, N + 1, K))

s1 = len(l1)
s2 = len(l2)

rev = int(s1**3)
if K % 2 == 0:
    rev += int(s2**3)
print(rev)

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:
import math


def main():
    N, K = [int(a) for a in input().split()]

    b = int(math.pow(N // K, 3))

    if K % 2 != 0:
        print(b)
        return

    b2 = math.pow(((N - K // 2) // K) + 1, 3)
    print(int(b + b2))


if __name__ == '__main__':
    main()

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)//K)**3)

Submission status: Accepted

Solution code:
def read():
    return raw_input().strip()
 
def read_ints():
    return map(int,read().split())
 
n,k = read_ints()
ans = 0
for x in range(1,n+1):
    if (2*x)%k == 0:
        m = (k-x) % k 
        ways = (n-m)/k + 1 
        if m == 0:
            ways -= 1 
        ans += ways*ways 
        
print ans

Submission status: Accepted

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

ans = 0
for a in range(1,n+1,1):
    m = (k - a % k) % k
    if (m+m) % k == 0 and n >= m:
        x = (n - m) // k + 1
        if m == 0: x -= 1
        ans += x*x
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

x = N//K
y = N%K

ans = x**3

if K%2 ==0:
    if K/2 <= y:
        ans+=(x+1)**3
    else:
        ans+=x**3

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

cand_dict = defaultdict(list)
for i in range(1, n + 1):
    if ((i % k) * 2) % k == 0:
        cand_dict[i % k].append(i)

ans = 0
for i in cand_dict.values():
    ans += len(i) ** 3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b=map(int, input().split())
try:
    c = a // (b // 2)
    c = c //2 + c%2
except Exception as  e:
    c = 0
if b % 2 == 1:
    c = 0
try:
    d = a // b
except Exception as e:
    d = 0
print(c**3 + d**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import floor
from math import ceil

N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
    if (i*2) % K == 0:
        m = floor((N+i)/K) - ceil((1+i)/K) + 1
        n = floor((N-i)/K) - ceil((1-i)/K) + 1
        ans += m*n
print(ans)