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())
x = 0
y = 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:
    y = 0
print(x**3 + y**3)

Submission status: Accepted

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

ans += syo**3
print(ans)

Submission status: Accepted

Solution code:
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
res = (n // k) ** 3
if k % 2 == 0:
    res += ((n % k >= k // 2) + (n // k)) ** 3
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC108C
n,k=list(map(int,input().split()))
if k%2!=0:
    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_mod0 = n // k
num_modk2 = (n + k//2) // k

if k % 2 == 0:
  total = num_mod0**3 + num_modk2 ** 3
else:
  total = num_mod0**3
print(total)

'''
Pairs_mod = []
for moda in range(0, k // 2 + 1):
  modb = (k - moda) % k
  for modc in range(k):
    #print(moda, modb, modc)
    if (modc + moda) % k == 0 and (modc + modb) % k == 0:
      Pairs_mod.append([moda, modb, modc])
print(Pairs_mod)
'''

Submission status: Accepted

Solution code:
import sys
from collections import deque
from itertools import permutations
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
l1 = deque([])
l2 = deque([])
ans = deque([])
c = K

while c <= N:
    l1.append(c)
    c += K
ans = len(l1) ** 3

if K % 2 == 0:
    c = K / 2
    while c <= N:
        l2.append(c)
        c += K
ans += len(l2) ** 3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = (int(x) for x in input().split())
"""cnt=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 & b<=c:
				#print(a,b,c)
				if (a+b)%k is 0 and (b+c)%k is 0 and (c+a)%k is 0:
					if a is b and b is c and c is a:
						cnt += 1
					elif a is b or b is c or c is a:
						cnt += 3
					elif a is not b and b is not c and c is not a:
						cnt += 6
					else: 
						print(f**k)

print(cnt)
"""
cnt=0
cnt2=0
for i in range(1,n+1):
  if k % 2 is 1:
  	if i % k is 0:
  		cnt += 1
  else:
  	if i % k is 0:
  		cnt += 1
  	elif i % k == int(k/2):
  		cnt2 += 1

#print(cnt,cnt2)
tmp = cnt*cnt*cnt +cnt2*cnt2*cnt2
print(tmp)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ans = 0
count_0 = 0
count_K_2 = 0
for i in range(1,N+1):
    if K % 2 != 0:
        if i % K == 0:
            count_0 += 1
        else:
            pass
    else:
        if i % K == 0:
            count_0 += 1
        elif i % K == K / 2:
            count_K_2 += 1

ans = pow(count_0,3) + pow(count_K_2,3)

print(ans)

Submission status: Accepted

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

half = 0
zero = 0


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

    if K % 2 == 0 and i % K == int(K/2):
        half += 1


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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if K % 2 == 0:
    # Kで割った時の余りが0のもの
    ans = (N // K) ** 3
    # Kで割った時の余りがK/2のもの
    ans += ((N + K // 2) // K) ** 3
else:
    ans = (N // K) ** 3

print(ans)

Submission status: Accepted

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

X = [x for x in range(1,N+1)]
Xn = [x for x in X if x % K == 0]

c_odd = 0
c_even1 = 0
c_even2 = 0

for x in X:
    if x % K == 0:
        c_odd += 1
        c_even1 += 1
    elif x % K == K/2:
        c_even2 += 1

if K % 2 != 0:
    ans = c_odd ** 3
else:
    ans = c_even1 ** 3 + c_even2 ** 3
      
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if K % 2 != 0:
    ans = (N // K) ** 3
else:
    k = K / 2
    x = N // k
    if x % 2 == 0:
        ans = 2 * (x / 2) ** 3
    else:
        ans = ((x // 2) + 1) ** 3 + (x // 2) ** 3

print(int(ans))

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    if(k&1):
        s=n//k
        print(s**3)
    else:
        s=n//k
        t=(n+k//2)//k
        print(s**3+t**3)
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    if(k&1):
        s=n//k
        print(s**3)
    else:
        s=n//k
        t=(n//(k//2)+1)//2
        print(s**3+t**3)
resolve()

Submission status: Accepted

Solution code:
import sys
from functools import reduce
from operator import mul
import math

def nCr(n, r):
    r = min(r, n-r)
    upper = reduce(mul, range(n, n-r, -1), 1)
    lower = reduce(mul, range(r, 0, -1), 1)
    return upper // lower


def oddCaseK(n, k):
    cand = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand += 1
    
    number_of_possibles = 0
    if cand >= 1:
        number_of_possibles += cand
    if cand >= 2:
        number_of_possibles += nCr(cand, 2) * nCr(2, 1) * 3
    if cand >= 3:
        number_of_possibles += nCr(cand, 3) * math.factorial(3)
    
    return number_of_possibles



def evenCaseK(n, k):
    cand1 = 0
    cand2 = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand1 += 1
        elif x % k == k // 2:
            cand2 += 1
    
    number_of_possibles = 0
    for cand in [cand1, cand2]:
        if cand >= 1:
            number_of_possibles += cand
        if cand >= 2:
            number_of_possibles += nCr(cand, 2) * nCr(2, 1) * 3
        if cand >= 3:
            number_of_possibles += nCr(cand, 3) * math.factorial(3)

    return number_of_possibles


def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
    if k % 2 == 0:
        ans = evenCaseK(n, k)
    else:
        ans = oddCaseK(n, k)
    
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from functools import reduce
from operator import mul
import math

def nCr(n, r):
    r = min(r, n-r)
    upper = reduce(mul, range(n, n-r, -1), 1)
    lower = reduce(mul, range(r, 0, -1), 1)
    return upper // lower


def oddCaseK(n, k):
    cand = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand += 1
    
    number_of_possibles = 0
    if cand >= 1:
        number_of_possibles += cand
    if cand >= 2:
        number_of_possibles += nCr(cand, 2) * nCr(2, 1) * 3
    if cand >= 3:
        number_of_possibles += nCr(cand, 3) * math.factorial(3)
    
    return number_of_possibles

    

def evenCaseK(n, k):
    cand1 = 0
    cand2 = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand1 += 1
        elif x % k == k // 2:
            cand2 += 1
    
    number_of_possibles = 0
    number_of_possibles = 0
    if cand1 >= 1:
        number_of_possibles += cand1
    if cand1 >= 2:
        number_of_possibles += nCr(cand1, 2) * nCr(2, 1) * 3
    if cand1 >= 3:
        number_of_possibles += nCr(cand1, 3) * math.factorial(3)

    if cand2 >= 1:
        number_of_possibles += cand2
    if cand2 >= 2:
        number_of_possibles += nCr(cand2, 2) * nCr(2, 1) * 3
    if cand2 >= 3:
        number_of_possibles += nCr(cand2, 3) * math.factorial(3)

    return number_of_possibles


def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
    if k % 2 == 0:
        ans = evenCaseK(n, k)
    else:
        ans = oddCaseK(n, k)
    
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

# mod で分類
mod_lst = [N // K for _ in range(K)]
for i in range(N % K):
	mod_lst[-(i + 1)] += 1
ans = 0

ans += mod_lst[0] ** 3

if K % 2 == 0:
	ans += mod_lst[K // 2] ** 3
	
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

N, K = map(int, input().split())
mod = [0] * K
for i in range(1, N + 1):
  mod[i % K] += 1
res = 0
#print(mod)
for x in range(K):
  t = mod[x] * mod[(K - x) % K]
  y = (-x) % K
  z = (-((K - x) % K)) % K
  if y == z:
    t *= mod[y]
    res += t
print(res)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
if K%2==1:
    q=N//K
    ans=q**3
else:
    q=N//(K//2)
    odd=(q+1)//2
    even=q//2
    ans=odd**3+even**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/2) == 0:
        b += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

x = n//k
y = x if k%2 else n//(k//2)

print(x**3+(y-x)**3)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ans = cnt_k**3
if K % 2 == 0:
    ans += cnt_k_half**3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

l=[N//K+1 if i<N%K else N//K for i in range(K)]

ans=0
for a in range(1,K+1):#1,3
    b=(K-a)%K#あまり
    c=(K-a)%K
    if (b+c)%K==0:
        ans+=l[a-1]*l[b-1]*l[c-1]
    else:
        continue

print(ans)

Submission status: Accepted

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

candidates = []
even = []
odd = []
for i in range(1, N+1):
    if i % K == 0:
        even.append(i)
        continue
    
    if K % 2 == 0 and i % (K // 2) == 0:
        odd.append(i)
        continue
    
count = len(even) ** 3

if K % 2 == 0:
    count += len(odd) ** 3
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# 2(a+b+c) はKの倍数
# Kが２でない時、
# Kが奇数ならa,b,cは全てKの倍数
# Kが偶数ならa,b,cは全てKの倍数か、全てK//2の倍数
# Kが２の時
if K == 2:
    print((N//2)**3 + ((N+1)//2)**3)
elif K % 2 != 0:
    a = N//K
    print(a**3)
else:
    a = N//K
    b = N//(K//2) - N//K
    print(a**3 + b**3)

Submission status: Accepted

Solution code:
N, K = map(int, 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:
if __name__ == '__main__':
    N, K = map(int, input().split())
    
    # Kの倍数の数
    mod_0 = N//K
    
    # mod K が K/2
    mod_half = 0
    if K%2 == 0:
        for n in range(1, N+1):
            if n%K == K//2:
                mod_half += 1
    
    print(mod_0**3 + mod_half**3)

Submission status: Accepted

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

c = N//K
ans = c**3
if K % 2 == 0:
    K2 = K//2
    m = 0
    while (2*m+1)*K2 <= N:
        m+=1
    ans += m**3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
h,f,ans=0,k,0
o=[]
e=[]
if k%2==0:
  h=k//2
  for i in range(n//h):
    if i%2==0:
      o.append((i+1)*h)
l=len(o)
if l>2:
  ans+=l*(l-1)*(l-2)
if l>1:
  ans+=l*(l-1)*3
ans+=l
for i in range(1,n//f+1):
  e.append(i*f)
l=len(e)
if l>2:
  ans+=l*(l-1)*(l-2)
if l>1:
  ans+=l*(l-1)*3
ans+=l
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# Kの偶奇で場合分け
# 偶数の場合は、abcすべてがKの倍数。もしくはabcすべてがKの倍数+1/2K
if K % 2 == 0:
  x = N // (K // 2)
  y = N // K
  print((x-y)**3 + y**3)
# 奇数の場合はabcすべたがKの倍数
else:
  x = N // K
  print(x**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N, K = map(int, input().split())
dic = defaultdict(int)
m = 0

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

ans = 0
for k in dic.keys():
  ans += dic[k]**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a=[]
for i in range(K):
    if (K-i)*3%K==i and (K-i)*2%K==0:
        a.append(i)

b=[]
for i in range(len(a)):
    b.append((N-a[i])//K+1)
b[0]-=1

print(sum([i**3 for i in b]))

Submission status: Accepted

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

if k%2==0:
  print(int((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())
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
check=n*2//k


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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list_even = []
abc_list_odd = []

for a in range(1, N+1):
    if (2*a)%K == 0:
        if ((2*a)//K)%2 == 0:
            abc_list_even.append(a)
        else:
            abc_list_odd.append(a)

print(len(abc_list_even)**3 + len(abc_list_odd)**3)

Submission status: Accepted

Solution code:
import itertools

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

# 2a = xk, 2b = ykのとき a+b = (x+y)k/2
# x+yが偶数、すなわちx,yの偶奇が一致するならばa+bはkの倍数となる。他の組合せでも同様
# a,b,cの候補リストを用意して重複順列計算

abc_list_even = []
abc_list_odd = []

for a in range(1, N+1):
    if (2*a)%K == 0:
        if ((2*a)//K)%2 == 0:
            abc_list_even.append(a)
        else:
            abc_list_odd.append(a)

print(len(abc_list_even)**3 + len(abc_list_odd)**3)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement

def calc_cases(num):
  cases = num
  if num == 2: cases += num*(num-1)*3
  elif num >= 3: cases += num*(num-1)*3 + num*(num-1)*(num-2)
  return int(cases)

N,K = map(int,input().split())
num, num2 = 0, 0
if K%2 ==1:
  for i in range(1,N+1):
    if i%K == 0: num +=1
else:
  for i in range(1,N+1):
    if i%K == 0:
      num +=1
    elif i%K == K//2:
      num2 += 1

print(calc_cases(num)+calc_cases(num2))
#print(num, calc_cases(num), num2, calc_cases(num2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

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

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

Submission status: Accepted

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

if k % 2 == 1:
    L = [i for i in range(k, n+1, k)]
    num = len(L)
    print(num**3)
else:
    L1 = [i for i in range(k, n+1, k)]
    L2 = [i for i in range(k//2, n+1, k)]
    num1 = len(L1)
    num2 = len(L2)
    print(num1**3 + num2**3)

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:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

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

ans = 0

if k%2==0:
    tmp = int(n//k)
    ans += tmp*tmp*tmp

    tmp = int((n+k/2)//k)
    ans += tmp*tmp*tmp
else:
    tmp = int(n//k)
    ans += tmp*tmp*tmp

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
mod_count = {}
a = n//k
b = n%k
for i in range(k):
    count = a
    if (1<=i<=b):
        count +=1
    mod_count[i]=count
ans = 0
for ai in mod_count.keys():
    bi = (k - ai)%k
    ci = (k - ai)%k
    if (bi+ci)%k ==0:
        ans += mod_count[ai]*mod_count[bi]*mod_count[ci]
    else:
        continue
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

a = n//k
b = (n+k//2)//k
print(a**3+b**3)

Submission status: Accepted

Solution code:

def solve(N, K):
    M = N//K
    rem = 0

    ans = M ** 3

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

    return ans


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

Submission status: Accepted

Solution code:
import itertools

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


if __name__ == "__main__":
    test()

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
import math
N, K = map(int, input().split())
if K%2 == 1:
    n = math.floor(N/K)
    print(n**3)
else:
    n1 = math.floor(N/K)
    k = K/2
    n2 = (math.floor(N/k)+1)//2
    print(n1**3 + n2**3)

Submission status: Accepted

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

Submission status: Accepted

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

# K|2a,2b,2cなので
# K:oddのときは2とKが互いに素なのでK|a,b,c
# よってa,b,cがN以下のKの倍数となる個数を数えれば良い
# K:evenのときはK=2L,L=K/2としてK/2|a,b,c
# ただしKで割った時のあまりは一致していないと条件を満たさない
# よってa,b,cがN以下のKの倍数となる個数と、N以下のKで割ってK/2余る個数を数えれば良い
# N以下のKで割ってK/2余る個数は(N + K/2)//Kで求まる
if K % 2 == 1:
    ans = (N // K) ** 3
else:
    ans = (N // K) ** 3 + ((N + K // 2) // K) ** 3

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

if b%2 == 1:
    c = a//b
    ans = c**3
else:
    c = a//b
    ans = c**3

    d = b//2
    e = (a-d)//b
    ans += (e+1)**3

print(ans)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

ret = 0

memo = [0 for _ in range(K)]

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

# only mod(0)     ex. mod(0) + mod(0) = mod(0)
ret += memo[0] ** 3

# only mod(K/2) when K is even  ex. mod(K/2) + mod(K/2) = mod(0)
if K % 2 == 0:
    ret += memo[K // 2] ** 3

print(ret)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split(' ')))
odds = 0
evens = 0
for i in range(1, N+1):  # 2e5
  if i % K == 0:  # (a+b) % k == 0 and ... => (a*k + b*k) % k = 0
    odds += 1
  elif K % 2 == 0 and i % (K//2) == 0:  # (a*(K/2) + b*(K/2)) % k | a, b >= 1, 
    evens += 1
print(odds ** 3 + evens ** 3)

Submission status: Accepted

Solution code:
import math

n,k=map(int,input().split())
if k%2!=0:
    nums=math.floor(n/k)
    print(nums**3)
 
else:
    nums1=math.floor(2*n/k)

    if nums1%2==0:
        a=int(nums1/2)
        b=nums1-a
        print(a**3+b**3)
    
    
    if nums1%2!=0:
        a=int((nums1+1)/2)
        b=nums1-a
        print(a**3+b**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
count,point=0,0
if k%2!=0:
    while k*(count+1)<=n:
        count +=1
    print(count**3)
else:
    for i in range(1,n+1):
        if i%k==0:point +=1
        elif i*2%k==0:count +=1
    print(count**3+point**3)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
count=0
point=0
if k%2!=0:
    while k*(count+1)<=n:
        count +=1
    print(count**3)
else:
    for i in range(1,n+1):
        if i%k==0:
            point +=1
        elif 2*i%k==0:
            count +=1
    print(count**3+point**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
line = raw_input()
N, K = [int(s) for s in line.split(' ')]
ret = []
if K % 2 == 1:
    count = N // K
    print count * count * count
else:
    k = K / 2
    count = int(math.ceil(N / k))
    odds = count // 2
    evens = count - odds
    all_counts = odds * odds * odds + evens * evens * evens
    print all_counts

Submission status: Accepted

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

Submission status: Accepted

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

mod0 = N // K
if K % 2 == 0:
    modk2 = mod0
    if N % K >= K // 2:    modk2 += 1 
else:
    modk2 = 0

print(mod0**3 + modk2**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

# print('input >>')
N, K = map(int, (input().split()))

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

Acount = Counter(A)
# print('ACount %s' % Acount)
ans = 0
for mod, times in Acount.items():
    mod_anti = K - mod
    if (K - mod) * 2 % K == 0:
        ans += Acount[mod] ** 3

# print('----------output----------')
print(ans)

Submission status: Accepted

Solution code:
# ABC108 C - Triangular Relationship
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)**3 + ((n+k//2)//k)**3
print(ans)

Submission status: Accepted

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


else:
    num=n//k
    ans=num**3
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if k%2==0:
    print(count0**3+count1**3)
else:
    print(count0**3)