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

v = 0
t = (2*N) // K
s = N // K

if K % 2 == 0:
    if t % 2 == 0:
        v = 2*((t/2)**3)
    else:
        v = (((t+1)/2)**3) + (((t-1)/2)**3)
else:
    v = s**3

v = int(v)
print(v)

Submission status: Accepted

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

if K % 2 == 0:
    ns1 = [i for i in range(1, N+1) if i % K == 0]
    ns2 = [i for i in range(1, N+1) if i % K == K//2]
    print(len(ns1)**3 + len(ns2)**3)
else:
    ns = [i for i in range(1, N+1) if i % K == 0]
    print(len(ns)**3)

Submission status: Accepted

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

ks = [x for x in range(1, n+1) if x % k == 0]

if k % 2 == 0: # if even
    k2s = [x for x in range(1, n+1) if x % (k//2) == 0 and x % k != 0] 
    print(len(ks) ** 3 + len(k2s) ** 3)
else:
    print(len(ks) ** 3)

Submission status: Accepted

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

if 2*n<k:
    print(0)
elif k%2 == 1:
    m = int(n/k)
    print(m**3)
else:
    m = int(n/k)
    l = int((n+k/2)/k)
    print(m**3+l**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
    n, k = map(int, string.split(" "))
    ans = 0
    """
    for a in range(1, n + 1):
        for b in range(1, n + 1):
            for c in range(1, n + 1):
                if (a + b) % k == 0 and (b + c) % k == 0 and (c + a) % k == 0:
                    ans.append((a, b, c))
    """
    if k % 2 == 1:
        ans = (n // k)**3
    else:
        ans = (n // k)**3 + ((n // k) + 1)**3 if n % k >= (k // 2) else 2 * ((n // k)**3)
    return str(ans)


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

Submission status: Accepted

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

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 = map(int, input().split())
print(sum(((N+a%K)//K)**2 for a in range(1,N+1) if (2*a)%K==0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

N, K = [int(i) for i in stdin.readline().rstrip().split()]

ans = 0
for a in range(1, N + 1):
    r = a % K
    if 2 * r % K == 0:
        ans += ((N + r) // K)**2

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

Submission status: Accepted

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

else:
    tmp = (int(N/K))**3
    e=0
    t = K
    while t % 2 == 0:
        t /= 2
        e += 1
    
    m = K / 2
    cnt = 0
    for i in range(2 ** (e-1), N+1, 2 ** e):
        if i % m == 0:
            cnt += 1
    n = int((N+1) / 2)

    print ((int(N/K))**3 + (int(cnt))**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ddd = list(map(int, input().split()))
n = ddd[0]
k = ddd[1]
count = 0

for i in range(n):
    a = i + 1
    if k % 2 == 1:
        if a % k != 0:
            bccount = 0
        else:
            bccount = (n // k) ** 2
    else:
        if a % k == 0:
            bccount = (n // k) ** 2
        elif a % k == k // 2:
            if n % k < k // 2:
                bccount = ((n // (k // 2)) // 2) ** 2
            else:
                bccount = ((n // (k // 2)) // 2 + 1) ** 2
        else:
            bccount = 0
    count = count + bccount

print(count)

Submission status: Accepted

Solution code:
from math import ceil, floor
N, K = map(int, input().split())
r = floor((2 * N) / K)
ans = floor(N / K)**3 if K % 2 == 1 \
    else ceil(r / 2) * (floor((2 * N - K) / (2 * K)) + 1)**2 + floor(r / 2) * floor(N / K)**2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

num = [x for x in range(0, n+1, k)]
ans = (len(num)-1) ** 3

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

Nlst = []
Nlst_gu = []
# for i in range(1,N+1):
#     Nlst.append(i)

if K % 2 == 0:
    for i in range(1,N+1):
        if i % K == 0:
            Nlst.append(i)
        elif i % (K/2) == 0:
            Nlst_gu.append(i)
else:
    for i in range(1,N+1):
        if i % K == 0:
            Nlst.append(i)
#
# print(Nlst)
# print(Nlst_gu)

ans = len(Nlst)
ans_gu = len(Nlst_gu)

print(ans * ans * ans + ans_gu * ans_gu * ans_gu)

#
# tmplst = []
# for i in itertools.product(Nlst, repeat=3):
#     tmplst.append(i)
#
# ans = 0
#
# for (a,b,c) in tmplst:
#     if (a+b) % K == 0 and (b+c) % K == 0 and (c+a) % K == 0:
#         ans += 1
#
#
# print(ans)

Submission status: Accepted

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

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

else:
    s = n//k
    t = (n+k//2)//k
    print(s**3+t**3)

Submission status: Accepted

Solution code:
a=input()
n,k=map(int, a.split())
if 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())

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

Submission status: Accepted

Solution code:
N, K = map(int, input().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:
        res += num[a] * num[b] * num[c]
print(res)

Submission status: Accepted

Solution code:
# encoding: utf-8
N, K = map(int, input().split())

ans = 0
for a in range(1, N + 1):
    # find a (a, b, c)
    # maybe TLE
    # for b in range(1, N + 1):
    #     if (a + b) % K == 0: break
    # for c in range(1, K + 1):
    #     # c and c + K returns same result
    #     if (b + c) % K == 0 and (a + c) % K == 0: break
    #     else: continue
    # else:
    #     continue # next a
    if (K - 2 * a) % K: continue
    b = K - (a % K)
    c = K - b            
    # b_min, c_min
    b_min = K - (K - b) % K
    c_min = K - (K - c) % K
    # b_max, c_max
    b_max = N - (N - b_min) % K
    c_max = N - (N - c_min) % K
    # add
    # print(a, b, c, (b_min, b_max), (c_min, c_max))
    ans += ((b_max - b_min) // K + 1) * ((c_max - c_min) // K + 1)

print(ans)

Submission status: Accepted

Solution code:

iN , iK = [int(x) for x in input().split()]

if iK % 2 == 0 :
    iFK = int(iK / 2)
    # iFK の奇数だけの組と偶数だけの組
    iULimit = int(iN /iFK)
    if iULimit % 2 == 0:
        print (int(iULimit / 2 ) ** 3 * 2 )
    else:
        print( int((iULimit + 1 )/ 2) ** 3 + int((iULimit - 1)/2) ** 3)
else:
    #iKの倍数だけの組み合わせ
    iULimit = int( iN / iK )
    print(iULimit ** 3)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    """
    1 <= N, K <= 2 * 10^5

    a,b,c (ok: a=b=c)

    """
    N, K = map(int, input().split())
    ans = f(N, K)
    assert ans == loop(N, K)
    # ans = TLE(N, K)
    print(ans)


def f(N, K):
    """
    1: a + b = l * K
    2: b + c = n * K
    3: c + a = m * K

    1 + 2 = c + a + 2b = (l + n) * K, 2b = (l + n - m) * K
    2 + 3 = a + b + 2c = (n + m) * K, 2c = (n + m - l) * K
    3 + 1 = b + c + 2a = (m + l) * K, 2a = (m + l - n) * K

    K % 2 == 0
        b = (l + n - m) * K / 2 = 整数
        Kの倍数 or K / 2 の倍数
    K % 2 == 1
        b = (l + n - m) * K / 2 = not 整数
        Kの倍数
    """
    if K % 2 == 1:
        # K の倍数の個数(N>=1より)
        x = N // K
        ans = x ** 3
    else:
        x1 = N // K
        x2 = (N + K // 2) // K
        ans = x1 ** 3 + x2 ** 3

    return ans


def loop(N, K):
    x = [0] * K
    for i in range(1, N+1):
        # K で割ったあまりがある値になる1-Nまでの個数
        x[i % K] += 1

    res = 0
    for a in range(K):
        # a余る数, K-a余る数(a=0 のときb=c=Kなので余りにする)
        b = (K - a) % K
        c = (K - a) % K

        if (b + c) % K == 0:
            res += x[a] * x[b] * x[c]

    return res


def TLE(N, K):
    ans = 0
    for a in range(1, N+1):
        for b in range(1, N+1):
            for c in range(1, N+1):
                if (a + b) % K == 0 and \
                    (b + c) % K == 0 and \
                        (c + a) % K == 0:
                    ans += 1
    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
  a = N//K
  if K%2 == 1:
    print(a**3)
  else:
    if N%K >= K//2:
      print(a**3 + (a + 1)**3)
    else:
      print(a**3*2)
    
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math


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

p = int(math.floor(N / K))
total = p * p * p
# print(p)
# print(total)

if K % 2 == 0:
    q = int(math.floor((N + K/2) / K))
    total += q * q * q

print(total)

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    n,k = [int(x) for x in input().split()]

    ans = 0
    for i in range(1,k//2+1):
        a=i
        b=k-i
        if (a+a)%k == 0:
            ans += ((n-a)//k+1)*((n-b)//k+1)*((n-a)//k+1)
        if a==b:
            continue
        if (b+b)%k == 0:
            ans += ((n-a)//k+1)*((n-b)//k+1)*((n-b)//k+1)
    ans += (n//k)*(n//k)*(n//k)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    num = (N - start) // K + 1
    result += num
    if num == 2:
        result += num * (num - 1) * 3
    elif num > 2:
        result += num * (num - 1) * 3
        result += num * (num - 1) * (num - 2)
    print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
 
 
def main():
    n, k = map(int, input().split())
 
    div_k = n // k  # 1からnの %k == 0 の個数
 
    # 1からnの %k == k/2 の個数
    if k % 2 == 0:
        div_k_harf = n // (k // 2) - div_k
    else:
        div_k_harf = 0
 
    print(div_k ** 3 + div_k_harf ** 3)
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
	if k % 2 == 1:
		if k > n:
			print(0)
			return
		else:
			div = n // k
			print(div * div * div)
			return
	else:
		kk = k / 2
		div1 = n // k
		j = 0
		for i in range(1, n + 1):
			if i % k == kk:
				j += 1
		print(div1 * div1 * div1 + j * j * j)
		return
			
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input().split()
N = int(s[0])
K = int(s[1])

ans = N // K 
ans = ans ** 3

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

print(ans+ ans_ev )

Submission status: Accepted

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

ks = [i for i in range(k, n + 1, k)] #n以下のkの倍数のリスト

count = len(ks) ** 3 #a,b,c全てがkの倍数のときの組み合わせ

if k % 2 == 0:
  khalfs = [i for i in range(k // 2, n + 1, k)] #n以下で、kで割った余りがk / 2になる数のリスト
  count += len(khalfs) ** 3 #a,b,c全てが余りk / 2のときの組み合わせをcountに追加する

print(count)

Submission status: Accepted

Solution code:
# encoding utf 8

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

sum = 0
for i in range(1,n+1):
    if 2*i%k == 0:
        # print(sum)
        sum += 1

        max = int((n-i)/k)
        # print("i",i,"max",max)
        if max == 1:
            sum += 6
        elif max>1:
            sum += max*(1+max)/2*6

print(int(sum))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

def ln():
    return map(int, input().split())

N, K = ln()

tmp = 0
tmp2 = 0
for a in range(1,N+1):
    if a%K == 0:
        tmp += 1
if K%2 == 0:
    for a in range(1,N+1):
        if a%K == K//2:
            tmp2 += 1
ans = tmp**3 + tmp2**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split(' ')]
    
#p = list(range(K, N+1,K))
p = N//K

cnt = 0

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
n = int(N/K) #nはKの倍数の個数
m = int(2*N/K) #mはK/2の倍数の個数
if K % 2 == 1:
  print(n**3)
else:
  print(n**3+(m-n)**3)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
# coding: utf-8


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

    div_k = n // k  # 1からnの %k == 0 の個数

    # 1からnの %k == k/2 の個数
    if k % 2 == 0:
        div_k_harf = n // (k // 2) - div_k
    else:
        div_k_harf = 0

    print(div_k ** 3 + div_k_harf ** 3)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 108 C
N, K = map(int,input().split())

if K%2 == 0:
    s = 0
    t = 0
    for k in range(1,N+1):
        if k%K == 0:
            s += 1
        elif k%K == K//2:
            t += 1
    print(s**3+t**3)
else:
    s = 0
    for k in range(1,N+1):
        if k%K == 0:
            s += 1
    print(s**3)

Submission status: Accepted

Solution code:
def run(n, k):
    a = 0
    b = 0
    for i in range(n):
        if (i+1) % k == 0:
            a += 1
        elif (i+1) % k == k/2:
            b += 1
    if k % 2 == 1:
        # return (n//k)**3
        return a**3
    else:
        # a = (n//k)**3
        # b = (((n - k/2)//k)+1)**3
        # return a + b
        return (a**3) + (b**3)


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


def main():
    n, k = read_line()
    print(run(n, k))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

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

r = 0

# abc mod K -> all 0
k  = N // K
r += k * k * k

# abc mod K -> all K/2
if K % 2 == 0:
    k  = (N + K // 2) // K
    r += k * k * k

print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8


N, K = map(int,input().split())
if K % 2 == 0:
    a = K/2
    moto = 0
    while a <= N:
        a += K
        moto += 1
    ans = moto**3
    b = N // K
    ans += b**3
    print(ans)
else:
    b = N // K
    print(b**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os

def main():
    n, k = map(int, input().split())
    res = 0
    if k % 2 == 0 :
        kk = k // 2
        knum = n // k
        kknum = n // kk - knum
        res = knum ** 3 + kknum ** 3
    else:
        knum = n // k
        res = knum ** 3
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

N,K=map(int,input().split())
ans=0
ans2=0
if K%2==1:
    for i in range(1,N+1):
        if i%K==0:
            ans+=1


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


print(ans**3+ans2**3)

Submission status: Accepted

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

f = n // k
g = 0 if k%2 != 0 else (n-k//2)//k + 1
print(f**3+g**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc108c

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

if K % 2 != 0:
    num = [i for i in range(1, N+1) if i % K ==0]
    print(len(num)**3)
else:
    num = [i for i in range(1, N+1) if i % K == 0]
    half_num = [i for i in range(1, N+1) if i % K == (K/2)]
    print((len(num))**3 + len(half_num)**3)

Submission status: Accepted

Solution code:
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    n, k = na()

    '''
    for i in range(k, n+1, k):
        for j in range(k, n+1, k):
            if (i + j) % k == 0:
                for m in range(k, n+1, k):
                    if (i+m) % k == 0 and (j+m) % k == 0:
                        print(i, j, m)
    '''
    # kは奇数
    if k % 2 == 1:
        print((n // k) ** 3)
        return
    '''
    c = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            if (i + j) % k == 0:
                for m in range(1, n+1):
                    if (i+m) % k == 0 and (j+m) % k == 0:
                        print(i, j, m)
                        c += 1
    '''
    # kは偶数
    c = (n//k) ** 3 + (n//(k//2) - n//k)  ** 3
    print(c)

main()

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
N = int(l[0])
K = int(l[1])
R1 = N // K
R2 = (N - (K // 2))// K + 1
if K % 2 == 1:
  print(R1**3)
else:
  print(R1**3 + R2**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
list_0 = []
list_k = []
for a in range(1,n+1):
  if k % 2 == 1:
    if a % k == 0:
      list_0.append(a)
  else:
    if a % k == 0:
      list_0.append(a)
    elif a % k == (k/2):
      list_k.append(a)
ans = len(list_0)**3 + len(list_k)**3
print(ans)

Submission status: Accepted

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

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

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:
def c_triangular_relationship(N, K):
    # 1からNの整数のうち、Kで割って0あまる数の個数
    reminder_K = N // K
    # 1からNの整数のうち、Kで割ってK/2あまる数の個数
    reminder_halfK = 0 if K % 2 == 1 else N // (K // 2) - reminder_K
    ans = reminder_K**3 + reminder_halfK**3  # 重複順列の公式より
    return ans

N, K = [int(i) for i in input().split()]
print(c_triangular_relationship(N, K))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
ans = 0
# Kが奇遇により処理変化
if K % 2 != 0:
    # 奇数の場合、a,b,cがいずれもKの倍数ならばOK
    ans = (N // K) ** 3

else:
    # 偶数の場合mod K が、K / 2 の倍数　または 0 ならOK
    h = K // 2
    cnt = 0
    ans = (N // K) ** 3
    for i in range(1, N + 1):
        if i % K == h:
            cnt += 1

    ans += cnt ** 3

print(ans)

Submission status: Accepted

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

ans = 0
t = 0

for i in range(k, n + 1, k):
    ans += 1

ans **= 3

if k % 2 == 0:
    for j in range(int(k / 2), n + 1, k):
        t += 1
    
    ans += t ** 3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

result = 0

if K % 2 == 1:
    c = N // K
    result = c ** 3
else:
    K2 = K // 2
    c1 = N // K
    c2 = N // K2 - c1
    result = c1 ** 3 + c2 ** 3

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K= list(map(int,input().split()))
import math
if K %2 ==0:
    std = K/2
else:
    std =K
M = N//std
M1 = N//K
if K%2==0:
    print(int((M-M1)**3+M1**3))
else:
    print(M1**3)

Submission status: Accepted

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

Submission status: Accepted

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

if ini[1] % 2 == 0:
    ans = (ini[0] / ini[1]) ** 3 + ((ini[0] / (ini[1] / 2) + 1)/2) ** 3
else:
    ans = (ini[0] / ini[1]) ** 3
print ans

Submission status: Accepted

Solution code:
from math import *
n,k=map(int,input().split())
dict1={}
flag=0
ans=0
if(k%3==0):
    flag=1
for i in range(1,n+1):
    try:
        dict1[i%k]+=1
    except:
        KeyError
        dict1[i%k]=1
for i in dict1.keys():
    if((i+i)%k==0):
        ans+=dict1[i]*dict1[i]*dict1[i]

print(ans)

Submission status: Accepted

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

# N, K = 3, 2

if K % 2 != 0:
    ans = (N // K)**3
else:
    full = []
    half = []
    for i in range(int(K/2), N+1, int(K/2)):
        if i % K == 0:
            full.append(i)
        else:
            half.append(i)

    ans = len(half) ** 3 + len(full) ** 3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *
n,k=map(int,input().split())
dict1={}
flag=0
ans=0
if(k%3==0):
    flag=1
for i in range(1,n+1):
    try:
        dict1[i%k]+=1
    except:
        KeyError
        dict1[i%k]=1
dict2={}
for i in dict1.keys():
    try:
        if(dict2[i]==1):
            a=1
    except:
        KeyError
        if((i+i)%k==0):
            ans+=dict1[i]*dict1[i]*dict1[i]
            dict2[i]=1
            dict2[k-i]=1
print(ans)