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())
cnt1, cnt2 = 0, 0
for i in range(1, n + 1):
    if i % k == 0:
        cnt1 += 1
    elif i % (k // 2) == 0:
        cnt2 += 1

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
def run():
    N, K = map(int, sysread().split())

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

    val = N // K
    val = val ** 3
    ans += val
    print(ans)
if __name__ == "__main__":
    run()

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



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


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

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

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











if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# a + b = b + c = c + a = 0 mod k
# a + b * 2 + c = 0 mod k
# a * 2 + b + c = 0 mod k
# a + b + c * 2 = 0 mod k
# ➡　a, b, c全部 0 (mod k) or kが偶数なら全部k / 2 (mod k)でもよい

n, k = map(int, input().split())
cnt0 = 0
cnt1 = 0
for i in range(1, n + 1):
    if i % k == 0:
        cnt0 += 1
    if i % k == k // 2:
        cnt1 += 1
if k % 2 == 1:
    print(cnt0 ** 3)
else:
    print(cnt0 ** 3 + cnt1 ** 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 a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += num[a] * num[b] * num[c]
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Z = 0
H = 0
for i in range(N):
  if (i+1)%K == 0:
    Z += 1
  if K%2 == 0 and (i+1)%K == K//2:
    H += 1

print(Z**3+H**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k%2 == 1:
    kcnt = n//k
    ans = pow(kcnt,3)
    print(ans)

else:
    kcnt = n//k
    ans = pow(kcnt,3)

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

Submission status: Accepted

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

Submission status: Accepted

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

if K % 2 != 0:
    ans_odd = []
    for i in range(N):
        if ((i + 1) % K) == 0:
            ans_odd.append(i + 1)

    len_ans = len(ans_odd)
    print(len_ans * len_ans * len_ans)

else:
    ans_even_zero = []
    ans_even_k = []
    for i in range(N):
        if (i + 1) % K == 0:
            ans_even_zero.append(i + 1)
        elif (i + 1) % K == (K // 2):
            ans_even_k.append(i + 1)

    len_ans_even_zero = len(ans_even_zero)
    len_ans_even_k = len(ans_even_k)

    ans = len_ans_even_zero * len_ans_even_zero * \
        len_ans_even_zero + len_ans_even_k * len_ans_even_k * len_ans_even_k
    print(ans)

Submission status: Accepted

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

# In[6]:


import math


# In[1]:


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


# In[10]:


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


# In[ ]:

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
v0 = n//k
ans = v0**3
if k%2==0:
    ans += ((n+k//2)//k) **3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
ans = (n // k)**3
if k % 2 < 1:
    ans += (n // (k // 2) - n // k)**3
print(ans)

Submission status: Accepted

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

ans = pow(n // k, 3)
if k % 2 == 0:
    ans += pow(n // k + (n % k >= k // 2), 3)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    n, k = getList()
    ans = 0
    k1, k2 = 0, 0
    if k == 1:
        print(n ** 3)
        return
    for i in range(1, n+1):
        if i % k == 0:
            k1 += 1
        if i % k == k / 2:
            k2 += 1
    print(k1 ** 3 + k2 ** 3)
    return



def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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

X=(N//K)**3

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

N, K = list(map(int, input().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==0:
    num = N//K
    num2 =(N-K//2)//K+1
    ans = num**3+num2**3
else:
    num = N//K
    ans = num**3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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


def read():
    N, K = map(int, input().strip().split())
    return N, K


def solve(N, K):
    # Kの倍数の数
    nk = math.floor(N / K)
    if K % 2 == 1:
        return nk ** 3
    else:
        nhk = math.floor(N / (K//2))
        return nk ** 3 + (nhk - nk) ** 3


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

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

ans=0
if k%2==0:
    cnt=0
    k_d = k//2

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

    x=n//k
    ans+=(x**3) +(cnt**3)
else:
    x=n//k
    ans+=x**3

print(ans)

Submission status: Accepted

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

cnt = [0] * (n + 1)

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

if k % 2 == 0:
    ans = 0
    ans += cnt[0] * cnt[0] * cnt[0]
    if k // 2 <= n:
        ans += cnt[k // 2] * cnt[k // 2] * cnt[k // 2]
    print(ans)
else:
    print(cnt[0] * cnt[0] * cnt[0])

Submission status: Accepted

Solution code:
import sys, math
from itertools import combinations
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, K = mi()
    if K%2==1:
        print((N//K)**3)
    else:
        print((math.floor((N//(K//2))/2))**3+(math.ceil((N//(K//2))/2))**3)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N, K = map(int, input().split())
    answer = 0
    # m=(N以下の正整数であり、かつKの倍数であるものの個数)とする。
    m = N//K
    # aとbとcが全てKの倍数のとき
    # a,b,cがすべて同じ、うち2つが同じ、3つが相異なるときの場合の数。
    answer += m + m*(m-1)*3 + m*(m-1)*(m-2)

    # Kが偶数のときは、aとbとcが全てKを法として(K//2)に合同なときも条件を満たす。
    if K%2 == 0:
        # m=(N以下の正整数であり、かつKを法として(K//2)に合同なものの個数)とする。
        if m*K + K//2 <= N:
            m += 1
        answer += m + m*(m-1)*3 + m*(m-1)*(m-2)
    print(answer)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
a = n//k
if k % 2 == 0:
    b = n//(k//2) - a
else:
    b = 0

ans = a + max(a*(a-1)*3,0) + max(a*(a-1)*(a-2),0)
ans += b + max(b*(b-1)*3,0) + max(b*(b-1)*(b-2),0)
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

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


	if k%2:
		a=n//k
		b=0
	else:
		a=n//k
		b=n//(k//2)-a

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








if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n, k = readInts()
dic = defaultdict(int)
for i in range(1, n+1):
    dic[i%k] += 1
res = 0
for a in range(k):
    b = (k-a)%k
    c = (k-a)%k
    if ((b+c)%k != 0):
        continue
    #print(a,b,c)
    res += dic[a] * dic[b] * dic[c]
print(res)

Submission status: Accepted

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

if k == 1:
    print(n**3)
    exit()
if n == 1:
    print(1*(k==3))
    exit()
    
ans = 0
for i in range(n):
    a = i+1
    if 2*(i+1) % k == 0:
        lb = math.floor((a%k)/k)
        if a%k == 0:
            lb = 1
        ub = math.floor((n-a%k)/k)
        # print(a, (a%k)/k, (n-a%k)/k)
        ans += (ub-lb+1)**2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
cnt2 = 0
for k in range(1, N + 1):
    if k % K == 0:
        cnt += 1
    elif K % 2 == 0 and k % K == K // 2:
        cnt2 += 1

print(cnt ** 3 + cnt2 ** 3)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    num = [0] * k
    for i in range(1, n + 1):
        num[i % k] += 1
        
    if k % 2 != 0:
        print(pow(num[0], 3))
    else:
        print(pow(num[0], 3) + pow(num[k // 2], 3))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

if k % 2 == 0:
    mod = k // 2
    count_mod = 0
    count = 0
    for i in range(1,n+1):
        if i % k == 0:
            count += 1
            #print("zero",i)
        elif i % k == mod:
            count_mod += 1
            #print("mod",i)
    #print(count,count_mod)
    print(count**3 + count_mod ** 3)
else:
    count = 0
    for i in range(1,n+1):
        if i % k == 0:
            count += 1
    print(count ** 3)

Submission status: Accepted

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

ans = 0
#a,b,c = pk,qk,rk
pk = n//k
ans += pk**3

#a,b,c = pk/2,qk/2,rk/2
if k%2 == 0:
    qk = n//(k//2) - pk
    ans += qk**3

print(ans)

Submission status: Accepted

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

"""
a+b = K i
b+c = K j
c+a = K k
2(a+b+c) = K(i+j+k)

k%2=0ならば,
a+b+cはk//2の倍数でなければならない、かつ、差を取ると結局a,b,cがそれぞれk//2の倍数
でなければならい。それでa+b,b+c,c+dはｋの倍数だから、a,b,cはすべて偶数またはすべて奇数
でなければならない。

それ以外の場合、
a+b+cがkの倍数である必要があり、かつ差を取ると結局a,b,cがすべてkの倍数でなければ
ならない。
"""

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = pow(n // k, 3)
    if k % 2 != 0:
        print(res)
    else:
        res += pow((n + k // 2) // k, 3)
        print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    pi = 0
    for n in range(1, N + 1):
        if n % K == 0:
            pi += 1

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

    ret = pi ** 3
    if K % 2 == 0:
        ret += hf ** 3
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    cnt = defaultdict(int)
    for i in range(1, N + 1):
        cnt[i % K] += 1

    ret = 0
    for a in range(K):
        b = (K - a) % K
        c = (K - a) % K
        if (b + c) % K != 0: continue
        ret += cnt[a] * cnt[b] * cnt[c]
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, open(0).read().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())
print((n//k)**3 if k%2==1 else (n//k)**3+((n+k//2)//k)**3)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
mods=[0]*k
mods[0]=n//k
for i in range(1,k):
    mods[i]=(n-i)//k+1
ans=0

for i in range(k):
    if (2*k-i)%k == i:
        ans+=mods[i]**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    if K%2 == 1:
        ans = (N//K)**3
        print(ans)
        return
    Kdiv2list = N//(K//2)
    Klist = N//K
    ans = Klist**3 + (Kdiv2list-Klist)**3
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

# 偶数の時は初項が1/2、公差kの数列から選べる
x = (n - k // 2) // k + 1

print((n // k)**3 + x**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
if k % 2:
    ans = (n // k) ** 3
    print(ans)
else:
    # 全て偶数、or 全て奇数
    ans = ((n + k // 2) // k) ** 3 + (n // k) ** 3
    print(ans)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()

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

Submission status: Accepted

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
n,k=map(int,input().split())
if k%2==1:
    num=n//k
    print(num**3)
else:
    num=n//k
    num2=(n-k//2)//k+1
    print(num**3+num2**3)

Submission status: Accepted

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

a = N // K
b = N % K
ans = a ** 3

for i in range(1, K):
    if (2 * (K - i)) % K == 0:
        if i > b:
            if K - i > b:
                ans += a ** 3
            else:
                ans += a * ((a+1)**2)
        else:
            if K - i > b:
                ans += (a + 1) * (a ** 2)
            else:
                ans += (a + 1) ** 3

print(ans)

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    N,K = LMIIS()
    ans = 0

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

    #(N//K) ありうるKの倍数の数(0以外)

    #a,b,c,全部がKの倍数 のパターン
    ans += (N//K)**3
    #a,b,c,全部がKの倍数+K//2　のパターン
    ans += ((N-K//2)//K+1)**3
    print(ans)


    


    





    
main()

Submission status: Accepted

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

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

n_k = n // k
n_mod_k = n % k

def mod_k(x):
    res = n_k
    if x != 0 and x <= n_mod_k:
        res += 1
    elif x == 0 and n_mod_k == k:
        res += 1
    return res

ans = 0

for i in range(k):
    a_mod = i
    b_mod = -i % k
    c_mod = -i % k
    if (b_mod +c_mod) % k == 0:
        ans += mod_k(a_mod) * mod_k(b_mod) * mod_k(c_mod)

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 i%k==(k//2):
        b+=1
print(a*a*a if k%2==1 else a*a*a+b*b*b)

Submission status: Accepted

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

ans=0
for b in range(1,n+1):
    if((n+b)//k >0 and (2*b)%k==0):
        p=((n+b)//k)
        q=(-(-b//k)) if b%k!=0 else (b//k)+1
        ans+=( p - q + 1)**2

#         for i in range( q,p+1):
#             for j in range( q,p+1):
#                 print(i*k-b,b,j*k-b)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
# 1 ~ n で、kで割った余りがどれだけあるか
from collections import defaultdict
dic = defaultdict(int)
for i in range(1,n+1): # 0含んだらダメじゃん
    dic[i%k] += 1
res = 0
for a in range(k):
    # 余りで考える
    b = (k-a)%k
    c = (k-a)%k
    if ((b+c)%k != 0):
        continue
    res += dic[a]*dic[b]*dic[c]
print(res)

Submission status: Accepted

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

M = N // K
ans = M * (M - 1) * (M - 2) + M * (M - 1) * 3 + M

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

print(ans)

Submission status: Accepted

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

if k%2 == 0:
    q1, r1 = divmod(n, k)
    if r1 < k//2:
        q2 = q1
    else:
        q2 = q1+1
    ans = q2**3 + q1**3
else:
    q1, r1 = divmod(n, k)
    ans = q1**3
#print(q1, q2)
print(ans)