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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
import math
if k%2!=0:
    count = 0
    i = 1
    check = True
    while check:
        if n < k * i:
            check = False
        else:
            count += 1
            i += 1
    print(int(count**2*count))
elif k%2==0:
    count = 0
    i = 1
    check = True
    while check:
        if n < (k/2) * i:
            check = False
        else:
            count += 1
            i += 1
    if count%2!=0:
        ans_1 = math.ceil(count/2)
        ans_2 = math.ceil(count/2)-1
        print(int(ans_1**2*ans_1+ans_2**2*ans_2))
    elif count%2==0:
        ans = count/2
        print(int(ans**2*ans)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inputs = raw_input().replace("\n", "").split(" ")
N, K = map(int, inputs)
r = N // K 
q = N % K 

n_0_a = r

if K % 2 == 0:
    half_K = K / 2
    hasuu = 1 if half_K <= q else 0
    n_k_2_a = r + hasuu
else:
    n_k_2_a = 0

out = (n_0_a ** 3) + (n_k_2_a ** 3)
print out

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, K = tuple(int(i) for i in input().split())

n = int(N/K)
c1 = n**3

k_2 = K/2

if N < k_2:
    print(0)
elif K%2 != 0:
    print(c1)
else:

    if N < n*K + k_2:
        c2 = n**3
    else:
        c2 = (n+1)**3
    print(c1 + c2)

Submission status: Accepted

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

arr = [0]*(k);

for i in range(1,n+1):

	arr[i%k] += 1;

#print(*arr)
counter = 0;

for i in range(k):

	if 2*i % k == 0:

		if i==0:
			counter += pow(arr[0],3);

		else:
			if i!=k-i:
				counter += pow(arr[i],3)
				counter += 3*( pow(arr[i],2) * arr[k-i] )
			else:
				counter += pow(arr[i],3)
	#print(counter,i)

print(counter)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
q, m = divmod(n, k)
a = 0
b = 0
lst = list(range(1, k)[::-1]) + [k]
for i in lst:
    if (i*2)%k != 0:
        a_ = 0
    else:
        a_ = q+1 if i<=m else q
        a_ *= a_
    a += a_
    if i == k-m and i != k:
        b = a
print(a*q+b)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = n // k
q = n % k

M = [0 for i in range(k)]
if not q == 0:
    for i in range(1, q+1):
        M[i] = d + 1
    for i in range(q+1, k):
        M[i] = d
    M[0] = d
else:
    for i in range(k):
        M[i] = d

cnt = 0
cnt += M[0] ** 3
if k % 2 == 0:
    cnt += M[k//2] ** 3

print(cnt)

Submission status: Accepted

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

num = N // K
re = num ** 3
if K % 2 == 0:
    num2 = 1 + (N - K // 2) // K
    re += num2 ** 3
print(re)

Submission status: Accepted

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

count = 0

R = N % K

for a in range(1, N + 1):
	r = a % K
	if 2 * r % K == 0:
		if r == 0:
			count += (N // K) ** 2
		elif R >= r:
			count += (N // K + 1) ** 2
		else:
			count += (N // K) ** 2


print(count)

Submission status: Accepted

Solution code:
import sys
fin = sys.stdin.readline
from math import ceil

N, K = [int(elem) for elem in fin().split(' ')]

""" if K % 2 != 0:
    quotient = N // K
    print(quotient**3)
elif K % 4 == 0:
    pass    
 """

count = 0
for a in range(1, N + 1):
    if (2 * a) % K == 0:
        q_max = (N + a) // K
        q_min = ceil((a + 1) / K)
        q_num = (q_max - q_min) + 1
        count += q_num**2
    else:
        continue
print(count)

Submission status: Accepted

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

divList = [0 for i in range(k)]
for i in range(1, n+1):
    divList[i % k] += 1

# print(divList)

count = 0
for i in range(k):
    if (i*2) % k == 0:
        count += divList[i] ** 3
print(count)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
count = 0
for i in range(1, N+1):
    if K % 2 == 0:
        a = i * K/2
        if a >= N+1:
            break
        maxn = int((N + a) // K)
        minn = math.ceil(( a + 1) / K)
        maxln = int((N - a) // K)
        minln = max(math.ceil((1 - a) / K), 1- i)
        #print(a)
        #print(maxn)
        #print(minn)
        #print(maxln)
        #print(minln)
        count += (maxn - minn + 1) * (maxln - minln + 1)
    else:
        a = i * K
        if a >= N + 1:
            break
        maxn = int((N + a) // K)
        minn = math.ceil((a + 1) / K)
        maxln = int((N - a) // K)
        minln = max(math.ceil((1 - a) / K), 1 - i)
        # print(a)
        # print(maxn)
        # print(minn)
        # print(maxln)
        # print(minln)
        count += (maxn - minn + 1) * (maxln - minln + 1)


print(int(count))

Submission status: Accepted

Solution code:
a = [int(i) for i in input().split()]
 
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	if a[0]%a[1] < a[1] // 2:
		print ((a[0]//a[1])**3 + ((a[0]//a[1])**3))
	else:
		print ((1 + a[0]//a[1])**3 + ((a[0]//a[1])**3))

Submission status: Accepted

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

if k % 2 != 0:
  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())
answer = 0
for i in range(0,K) :
    if i*2 % K == 0 :
        if i != 0 :
            if i <= N%K :
                answer += (N//K+1)**3
            else :
                answer += (N//K)**3
        else :
            answer += (N//K)**3
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N, K = map(int, input().split())
    if K&1:
        return str((N//K)**3)
    else:
        i = K//2
        a, b = N//K, N%K
        c = a+(b>=i)-(i==0)
        return str(c**3+a**3)
    return str(m)

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

Submission status: Accepted

Solution code:
def calc(n, k, x):
    c = 0

    while x <= n:
        a  = (x - 1) // k
        c += 1 + 6 * (1 + a) * a // 2
        x += k

    return c

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

if k % 2 == 0:
    print(calc(n, k, k) + calc(n, k, k // 2))
else:
    print(calc(n, k, k))

Submission status: Accepted

Solution code:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]


n, k = LI()

print((n//k)**3 + (1-k%2)*((n - k//2)//k+1)**3)

Submission status: Accepted

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

list = []
p = 0

for a in range(1,n+1):
    x = int(a/k)
    y = int((n+a)/k)
    if  2*a % k ==0:
        p = p + (y-x)**2
    else:
        pass

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nk=input().split()
n=int(nk[0])
k=int(nk[1])
if k==1:
    print(n**3)
elif k%2==0:
    #あまりhalf
    h=int(k/2)
    x=(n-h)//k
    #あまり０
    y=n//k
    print((x+1)**3+y**3)
else:
    x=n//k
    print(x**3)

Submission status: Accepted

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

Submission status: Accepted

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

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

  A1 = (N - K2)//K
  A2 = N//K

  print((A1 + 1)**3 + (A2)**3)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
minus = []
for i in range(1,N+1):
    
    a = i
    b = i
    c = i
    if (a + b) % K == 0:
        count += 1
        count += len(minus) * (3*2)
        if len(minus) >= 2:
            #kumiawase = math.factorial(len(minus))/(math.factorial(len(minus)-2)*math.factorial(2))
            kazu = len(minus)
            kumiawase = kazu * (kazu - 1) / 2
            count += kumiawase * (3*2)
    if i % K == 0:
        minus.append(i)

print(int(count))

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
N,K = inpl()
co, ce = [],[]#
odd,even,heven = 0,0,0
for i in range(1, N+1):
    if i % K == 0:
        if i%2==0:
            even+=1
            #print(i,'even')#
            ce.append(i)#
        else:
            odd+=1
            #print(i,'odd')#
            co.append(i)
    elif 2 * i % K == 0:
        heven += 1
if K%2 == 1:
    print((even+odd+heven)**3)
else:
    print(even**3+odd**3+heven**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, k = list(map(int,input().split()))

ans = 0
mut_ori = n//k
for a in range(1, k + 1):
    b_cand = list(range(k - a%k,k+1,k))
    for b in b_cand:
        c_cand = list(range(k - b%k,n+1,k))
        for c in c_cand:
            if a <= n%k:
                mut = mut_ori + 1
            else:
                mut = mut_ori
            if b <= n%k:
                mut *= (mut_ori + 1)
            else:
                mut *= mut
            if (a + c) % k == 0:
                ans += mut
#             print(a,b,c,mut)
print(ans)

Submission status: Accepted

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

count = (N // K)**3

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

print(count)

Submission status: Accepted

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

ans=0
one = 0
three = 0
six = 0

th = n%k
roop = (n//k)
if k%2==0:
    semiroop = roop +(1 if th>=k/2 else 0)
else:
    semiroop = 0
rp=roop
one = rp
three = rp*(rp-1)
six = rp*(rp-1)*(rp-2)
#ans += one + 3*(three) + 6*(six)
ans += rp**3
rp = semiroop
one = rp
three = rp*(rp-1)
six = rp*(rp-1)*(rp-2)
#ans += one + 3*(three) + 6*(six)
ans+=rp**3
print(ans)

Submission status: Accepted

Solution code:
import math

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

d = math.floor(N/K)

ans = d ** 3

if K%2 == 0:
	ans += (d + math.floor((N - d*K)/(K/2))) ** 3

print(ans)

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
ans = 0
if b % 2 == 0:
    half = b // 2
    ex_half = a - half
    # print(ex_half)
    n_half = ex_half // b + 1
    # print(n_half)
    ans = ans + n_half
    if n_half >= 2:
        ans = ans + 3 * n_half * (n_half-1)
    if n_half >= 3:
        ans = ans + 6 * n_half * (n_half-1) * (n_half-2) // 6
else:
    pass
n_baisuu = a // b
# print(n_baisuu)
ans = ans + n_baisuu
if n_baisuu >= 2:
    ans = ans + 3 * n_baisuu * (n_baisuu-1) // 2 * 2
if n_baisuu >= 3:
    ans = ans + 6 * n_baisuu * (n_baisuu-1) * (n_baisuu-2) // 6
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  1 18:57:18 2018
ABC108C
@author: maezawa
"""

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

if k % 2 != 0:
    r = n // k
    print(r**3)
else:
    r1 = n // k
    r2 = n // (k//2) - r1
    print(r1**3+r2**3)

Submission status: Accepted

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

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

pos=n%k;
left=int(n/k+1);

ans=0;
p=0;

if k%2==0:
    if k/2<=pos:p=left;
    else: p=left-1;
    ans+= p**3;
if k<=pos:p=left;
else:p=left-1;
ans+= p**3;
print(int(ans));

Submission status: Accepted

Solution code:
#coding: utf-8

def com(a):
    return a**3

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

sho = n/k

if k%2 == 0:
    amari = n%k
    if amari >= (k>>1):
        print com(sho) + com(sho + 1)
    else:
        print com(sho) * 2
else:
    print com(sho)

Submission status: Accepted

Solution code:
def numMod(x):
    global N, K
    return N // K + 1 if N % K >= x else N // K

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = [0]*k
sum = 0

for i in range(1,n+1) :
   d[i%k] += 1

for a in range(k) :
   if (2*a)%k == 0 :
      sum = sum + d[a]**3

print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

count = 0
for a in range(1, N+1):
    # b, c in range(K - (a % K), N+1, K)
    # b + c == (i + j) * K - 2 * (a % K)
    # (2 * a) % K == 0

    if (2 * a) % K != 0:
        continue

    min_b = K - (a % K)
    n_b   = (N + K - min_b) // K
    count += n_b ** 2

print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

if k>n:
    if k%2==0 and 2*n>=k:
        print(1)
    else:
        print(0)
elif k%2==1:
    k2 = n//k
    print(k2**3)
else:
    n2 = n-k//2
    k3 = n2//k
    k2 = n//k
    print((k3+1)**3+k2**3)

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

Submission status: Accepted

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

def cnt_mod(i):
    if n % k >= i:
        cnt_i = n // k + 1
    else:
        cnt_i = n // k

    a = pow(cnt_i, 3)
    return a

def cnt_mode_zero():
    cnt_zero = n // k
    a = pow(cnt_zero, 3)
    return a


cnt = 0
cnt += cnt_mode_zero()
if k % 2 == 0:
    ans = cnt_mod(k/2)
    cnt += ans
print(cnt)

Submission status: Accepted

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

ans = [0, 0]
d = k // 2

for i in range(1, n+1):
    if k % 2 == 0 and i % k == d:
        ans[0] += 1
    if i % k == 0:
        ans[1] += 1

print(ans[0] ** 3 + ans[1] ** 3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


N,K = [int(x) for x in input().split()]

result = 0

if (K%2) == 1:
    kouho = N//K
    result+=kouho*kouho*kouho

else:
    kouho1 = N//K
    kouho2 = N//(K/2) - kouho1
    result+=kouho1*kouho1*kouho1
    result+=kouho2*kouho2*kouho2

print(int(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))-(n // k))**3)

Submission status: Accepted

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

    if k % 2 == 0:
        print(num ** 3 + num2 ** 3)
    else:
        print(num ** 3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N, K = map(int, input().split());
answer = 0;

margin = N//K;
answer += int(margin)**3;

if(K%2==0):
    N-=(K/2);
    margin = N//K;
    answer += int(margin+1)**3;

print(answer);

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 = [int(i) for i in input().split()]

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

elif k % 2 != 0:
  num = int(n / k)
  print(num ** 3)
  
else:
  num = int(n / k)
  num2 = int(int((n - k / 2)) / k + 1)
  print(num ** 3 + num2 ** 3)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

q = N // K

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

Submission status: Accepted

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

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

else:
    print((N // K) ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k % 2 != 0:
    num_mod_0 = n // k
    print(num_mod_0 ** 3)

else:
    num_mod_0 = n // k
    a = num_mod_0 ** 3

    num_mod_1 = n // (k/2) - n // k
    b = num_mod_1 ** 3

    print(int(a+b))

Submission status: Accepted

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

Submission status: Accepted

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

ans = (N // K)**3

if K % 2 == 0:
    q, r = divmod(N, K)
    if r >= K // 2:
        q += 1
    ans += q**3

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
f = lambda x: n//k + (x <= (n % k)) if x != 0 else n // k
res = 0
for a in range(k // 2 + 1):
    if (2 * (k - a)) % k == 0:
        res += f(a) * (f(((k - a)) % k) ** 2)
print(res)

Submission status: Accepted

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

r0 = int(N/K) # 余りが0のケースの数

r2 = 0
if K%2==0: # 偶数のときのみ可能性あり
    K2 = int(K/2) # このあまりにならなくてはいけない
    r2 = int(N/K2)
    r2 -= r0

result = r0*r0*r0 + r2*r2*r2
print(result)

Submission status: Accepted

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

zero=0
half=0
#余り0の数と余りK/2の数の個数を数える

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-


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

    ans = 0
    for a in range(1, n+1):
        if 2 * a % k == 0:
            d = a // k
            u = (n+a) // k
            ans += (u-d) ** 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import math

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

evens = n // k
k_halfs = (n + (k // 2)) // k

sum_a_even = evens * evens * evens

sum_a_odd = 0
if k % 2 == 0:
    sum_a_odd = k_halfs * k_halfs * k_halfs

print(sum_a_even + sum_a_odd)

Submission status: Accepted

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

Submission status: Accepted

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

n = N // K
if K % 2 == 0:
    if N % K >= K/2:
        # print("A")
        print((n+1)**3 + n**3)
    else:
        # print("B")
        print(n**3 + n**3)
else:
    # print("C")
    print(n**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n,k = (int(i) for i in input().split())  
answer = 0
answer += (n//k)**3
if k % 2 == 0:
    answer += ( (n + (k//2) ) // k )**3

print(answer)

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:
N, K = map(int, input().split())
if K%2 == 0:
    M = K//2
    sum = N//M
    opt1 = N//K
    ans = opt1**3 + (sum-opt1)**3
else:
    opt = N//K
    ans = opt**3
print(ans)

Submission status: Accepted

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

mods = [0] * K
for i in range(N):
  mods[i%K] += 1
#print(mods)

ans = 0
if K % 2 == 0:
  ans += mods[K//2 -1] ** 3

ans += mods[K-1] ** 3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

co=0
a0=n//k
co+=a0**3

if k%2==0:
    ah=(n+k//2)//k
    co+=ah**3

print(co)

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

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

Submission status: Accepted

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

f = n // k
ans = f**3

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

print(ans)

Submission status: Accepted

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

ans = 0

temp = n // k

ans += temp ** 3

if k % 2 == 0:
    n += k // 2
    temp = n // k
    ans += temp ** 3

print(ans)

Submission status: Accepted

Solution code:
def iin(): return int(input())
def nl(): return list(map(int, input().split()))
def ary(r, c, v): return [[v for _ in range(c)] for _ in range(r)]

n, k = nl()

d = dict()
for i in range(1, n + 1):
    t = i % k
    d[t] = d.get(t, 0) + 1

ans = 0
if k % 2 == 0:
    ans += d.get(k // 2, 0) ** 3
ans += d.get(0, 0) ** 3
print(ans)

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: Runtime Error

Solution code:
n, k = map(int, input().split())
num = [0] * n
for i in range(1, n+1):
    num[i % k] += 1
ans = 0
for a in range(k):
    b = (k-a) % k
    c = (k-a) % k
    if ((b+c) % k != 0):
        continue
    ans += num[a] * num[b] * num[c]
print(ans)

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

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

if K%2==0:
    d1=N//(N//2)
    d2=N//K
    ans=d2**3+(d1-d2)**3
else:
    d=N//K
    ans = d**3
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
ans = 0
extra = [0]*N
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)

Submission status: Runtime Error

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

ans = 0
extra = [0] * N
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)

Submission status: Runtime Error

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

ans = 0
extra = [0] * N
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] + extra[b] + extra[c]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

from collections import Counter
res = [x%K for x in range(1, N+1)]
res_sort = sorted(zip(Counter(res).keys(), Counter(res).values()))

if K%2==0:
    ans = res_sort[0][1]**3 + res_sort[K//2][1]**3
else:
    ans = res_sort[0][1]**3

print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
num = [0 for _ in range(N)]
for i in range(1, N + 1):
    num[i % K] += 1
ans = 0
for a in range(N):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += num[a] * num[b] * num[c]
print(ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
res=[0]*N
for i in range(1,N+1):
    res[i%K]=res[i%K]+1
#print(res)

if K%2==0:
    print(pow(res[K//2],3)+pow(res[0],3))
else:
    print(pow(res[0], 3))