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

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))




N, K = lr()
exact = N // K
answer = pow(exact, 3)
if K%2 == 0:
    half = N // (K//2) - exact
    answer += pow(half, 3)
print(answer)

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

Solution (Python):
from itertools import product
N, K = list(map(int, input().split()))


ans = 0

count = N // K

ans += count ** 3

if K % 2 == 0:
    count = 0
    k = K // 2
    while True:
        if k <= N:
            count += 1
            k += K
        else:
            break
    ans += count ** 3

print(ans)

Solution (Python):


import sys






















def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, k = mi()
    if k % 2 == 1:
        mod_k = n // k
        
        print(mod_k ** 3)
    else:
        mod_k_0 = n // k
        mod_k_div2 = n // k + (n % k) // (k // 2)
        print(mod_k_0 ** 3 + mod_k_div2 ** 3)


if __name__ == "__main__":
    main()

Solution (Python):
n, k = [int(x) for x in input().split()]
ans = (n // k) ** 3
if k % 2 == 0:
    ans += ((n + k // 2) // k) ** 3
print(ans)

Solution (Python):
n,k=map(int,input().split())
d=dict()
for i in range(k):
    d[i]=0
for i in range(1,n+1):
    d[i%k]+=1

if k%2!=0:
    print(d[0]*d[0]*d[0])
else:
    print(d[0]*d[0]*d[0]+d[k//2]*d[k//2]*d[k//2])

Solution (Python):
N, K = map(int, input().split())
K_multi = []
K_half_multi = []
ans = 0

if K % 2 == 0:
    K_half = K // 2
    for i in range(1, N+1):
        if i % K == 0:
            K_multi.append(i)
        elif i % K == K_half:
            K_half_multi.append(i)
else:
    for i in range(1, N+1):
        if i % K == 0:
            K_multi.append(i)

ans += len(K_multi)**3
ans += len(K_half_multi)**3

print(ans)

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

Solution (Python):
N, K = map(int, input().split())
num = [0 for _ in range(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)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True




def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)






def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

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

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

Solution (Python):
n,x = map(int,input().split())
count = 0
for i in range(1,n+1):
    if i*2 % x == 0:
        count += ((n+i)//x - i//x)**2
print(count)

Solution (Python):
def abc108_c():
  n, k = map(int, input().split())
  d, m = divmod(n, k)
  
  ans = d ** 3
  
  if k % 2 == 0:
    x = d
    if k // 2 <= m: x += 1
    ans += x ** 3
  print(ans)

abc108_c()

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

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

ans1=0
ans2=0

for i in range(1,n+1):
    if i%k==0:
        ans1+=1
    
    if i%k==k/2:
        ans2+=1

if k%2==0:
    print(ans1**3+ans2**3)
else:
    print(ans1**3)

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

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

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    n,k = map(int,input().split())
    if k%2 == 0:
        x = n//k
        k //= 2
        y = n//k
        ans = x*x*x - (x - y)*(x - y)*(x - y)
        print(ans)
    else:
        x = n//k
        print(x*x*x)
if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')
from math import ceil

def solve():
    N, K = MI()

    NmodK = N % K if N % K != 0 else K
    times = ceil(N / K)
    ans = 0
    for a in range(1, K+1):
        b = K - a if K - a > 0 else K
        c = b
        
        if (b + c) % K == 0:
            cnt_b = (N - b) // K + 1
            
            if a <= NmodK:
                t = times
            else:
                t = times - 1
            
            ans += cnt_b ** 2 * t
    print(ans)



if __name__ == '__main__':
    solve()

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


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

Solution (Python):

import sys


def solve(N: int, K: int):
    if K % 2 == 0:
        k2 = K // 2
        print(((N // k2 + 1) // 2) ** 3 + (N // K) ** 3)
    else:
        print((N // K) ** 3)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)


if __name__ == '__main__':
    main()

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

zero = 0
even = 0

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

ans = 0
ans += zero**3
ans += even**3

print(ans)

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

zero = 0
even = 0

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

ans = 0
ans += zero**3
ans += even**3


print(ans)

Solution (Python):
n, k = map(int,input().split())
mod_ary = [0] * k
for i in range(1,n+1):
    mod_ary[i%k] += 1

ans = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k != 0:
        continue

    ans += mod_ary[a] * mod_ary[b] * mod_ary[c]
print(ans)

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

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

ans = 0
for i in range(1,k):
    first = i
    second = k - i
    third = k - second
    if (first + third) % k == 0:
        ans += mod_ls[first] * mod_ls[second] * mod_ls[third]
ans += mod_ls[0] ** 3
print(ans)

Solution (Python):
n, k = map(int, input().split())
if k > n:
    if k % 2 == 0 and k // 2 <= n:
        print(1)
        quit()
    else:
        print(0)
        quit()
if k % 2 == 0:
    
    p1 = n // k
    p2 = (n + k // 2) // k
    ans = p1 ** 3 + p2 ** 3
    print(ans)
    quit()
p1 = n // k
print(p1 ** 3)

Solution (Python):
n,k=map(int,input().split())
def f(cnt):
  return cnt+3*cnt*(cnt-1)+cnt*(cnt-1)*(cnt-2)
if k%2!=0:
  cnt=n//k
  print(f(cnt))
else:
  cnt=n//k
  cnt2=0
  for i in range(n):
    i+=1
    if i%k==k//2:
      cnt2+=1
  print(f(cnt)+f(cnt2))

Solution (Python):
n,k=map(int,input().split())
if k%2!=0:
  cnt=n//k
else:
  cnt=n//k
  cnt2=0
  for i in range(n):
    i+=1
    if i%k==k//2:
      cnt2+=1
def f(cnt):
  if cnt==0:
    return 0
  elif cnt==1:
    return 1
  elif cnt==2:
    return 8
  else:
    return cnt+3*cnt*(cnt-1)+cnt*(cnt-1)*(cnt-2)
if k%2!=0:
  print(f(cnt))
else:
  print(f(cnt)+f(cnt2))

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

Solution (Python):
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    if K % 2 == 1:
        p = N // K
        ans = p ** 3
    else:
        p = N // K
        ans = p ** 3
        p = (N + K//2) // K
        ans += p ** 3

    print(ans)

if __name__ == '__main__':
    main()

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

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

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N,K = inputlist()
m0 = 0
mh = 0
ans = 0
for i in range(1,N+1):
    d = i%K
    if d == 0:
        m0+=1
    if d == K//2 and K % 2 == 0:
        mh +=1
print(m0**3 + mh**3)

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

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

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

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

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

ans = (n//k)**3

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

print(ans)

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

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

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

Solution (Python):
import sys

IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

def main():
    n, k = MII()
    cnt = (n//k)**3
    if k%2==0:
        cnt += ((n+(k//2))//k)**3
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):


nim, mike = map(int, input().split())
result = (nim//mike)**3
if mike % 2 == 0:
  result += ((nim+mike/2)//mike)**3
print(int(result))

Solution (Python):
def main():
  N, K = (int(_) for _ in input().split())
  if K%2 == 1:
    print(pow(N // K, 3))
    return
  a = N // K
  b = (N - K//2) // K + 1
  print(pow(a, 3) + pow(b, 3))
  return

if __name__ == '__main__':
  main()

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

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    return


def B():
    x1, y1, x2, y2 = LI()
    a = x2 - x1
    b = y2 - y1
    print(x2 - b, y2 + a, x1 - b, y1 + a)
    return


def C():
    n, k = LI()
    if k % 2:
        print((n // k)** 3)
    else:
        print(int((n//k)**3 + ((n-k/2)//k+1)**3))
        
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    C()

Solution (Python):
from collections import Counter
N,K=map(int,input().split())
m=[]
for i in range(1,N+1):
    m.append(i%K)
Cnt=Counter(m)
cnt=0
for a in range(K):
    r=(K-a)%K
    if((2*r)%K==0):
        cnt+=Cnt[r]**2*Cnt[a]
print(cnt)

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)


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


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)

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

if K % 2 == 1:
    num = N // K
    ans = num ** 3
else:
    K_ = K // 2
    num1 = N // K
    num2 = (N + K - K_) // K
    ans = num1 ** 3 + num2 ** 3

print(ans)

Solution (Python):
def sum(n,k):
    sum = 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:
                    if(a+c)%k == 0:
                        if(b+c)%k == 0:
                            sum += 1

n,k = map(int,input().split())
t0 = 0
t5 = 0 
for a in range(1,n+1):
    
    if(a%k == 0):
        t0 += 1
    elif(a/k)%(0.5)==0:
        t5 += 1

print(pow(t5,3)+pow(t0,3))

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

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

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

Solution (Python):
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
    c1 = n // k
    if (k & 1): cnt = pow(c1, 3)
    else: c2 = n // (k // 2); cnt = pow(c1, 3) + pow(c2 - c1, 3)
    print(cnt)

if __name__ ==  '__main__':
    main()

Solution (Python):





mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    
    n,k = readInts()
    NUM = [0] * k
    for i in range(1,n+1):
        NUM[i%k] += 1
    
    res = 0
    for a in range(k):
        
        
        
        
        b = (k-a) % k
        c = (k-a) % k
        if (b+c) %k != 0:
            continue
        res += NUM[a]*NUM[b]*NUM[c]
    print(res)





if __name__ == '__main__':
  main()

Solution (Python):
import sys

input = sys.stdin.readline
 
n, k =  map(int, input().split())

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

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

ans = 0
a = n//k
ans += a*(a-1)*(a-2) + 3*a*(a-1) + a

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

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

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

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

sign = k%2

if sign == 0:
  temp = 0
  for i in range(1,n+1):
    if i%k == k//2:
      temp = temp + 1  
  ans = (n//k)**3 + temp**3
elif sign == 1:
  ans = (n//k)**3
  
print(int(ans))

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



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

ans=0
if modk>=1:
  ans+=(modk)**3
if modhalf>=1:
  ans+=modhalf**3

print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def main():
    n, k = map(int, input().split())
    x = sum(2 * i % k == 0 for i in range(1, k))
    a, b = n // k, n % k
    y = sum(2 * i % k == 0 for i in range(k * a + 1, k * a + b + 1))
    c = x * a + y
    ans = (x * a + y) ** 3 + a ** 3
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, k = map(int, readline().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()

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

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

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

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

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

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

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

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

if k % 2 != 0:
    x = n // k
    print(x ** 3)
else:
    x = n // k
    y = 0
    for i in range(1, n + 1):
        if i % k == k // 2:
            y += 1
    print(x ** 3 + y ** 3)

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


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

res = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k != 0:
        continue
    res += num[a] * num[b] * num[c]

print(res)

Solution (Python):
import math
N,K=map(int,input().split())
ans=0

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	n, k = IN()
	rr=0
	if k%2==0:
		pp=(n+(k//2)) // k
		
		rr+=pp**3
		
	pp = n//k
	
	rr += pp**3
	
	print(rr)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

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



ans+=((n//k)**3)

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

print(ans)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()

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

ans = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k != 0:
        continue
    ans += m[a] * m[b] * m[c]

print(ans)

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

Solution (Python):
import math

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

if K%2==1:
    print((N//K)**3)
else:
    all=N//(K/2)
    even=math.floor(all/2)
    odd=math.ceil(all/2)
    print(even**3+odd**3)

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

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

Solution (Python):
import sys





from fractions import gcd








readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

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

Solution (Python):

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






if K == 1:
    
    print(pow(N,3))
else:
    
    
    
    
    
    ans = pow(int(N/K),3)
    
    if K%2 == 0:
        
        
        
        
        
        
        n_limit = int(N/K - 1/2)
        
        if K/2 <= N:
            
            ans += pow(n_limit + 1,3) 
    
    print(ans)

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

Solution (Python):
from itertools import product
N,K=map(int, input().split())

num = [0 for k in range(K)]


for n in range(1, N+1):
  num[n%K] += 1

ans = 0

for a in range(len(num)):
  b = (K-a) % K
  c = (K-a) % K
  if (b + c) % K == 0:
    ans += num[a] * num[b] * num[c]

print(ans)

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

Solution (Python):





from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product


import sys
sys.setrecursionlimit(10 ** 5 + 10)


def resolve():
    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 2*(i%K)==K:
                cnt+=1
        print(cnt**3+(N//K)**3)




resolve()

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N,K=map(int,readline().split())

    if K%2!=0:
        print((N//K)**3)
    else:
        count=0
        L=K//2
        count+=(N//L-N//K)**3
        count+=(N//K)**3
        print(count)
        
if __name__=="__main__":
    main()

Solution (Python):
'''
（１）2つの数の和がKの倍数になる条件
aとbがともにKの倍数である
aとbの mod K の和がKの倍数である
（２）3つの数の内、どの2つを足してもKの倍数になる条件
3つの数全てがKの倍数である
3つの数全てのmod K がK/2である
（３）Kが奇数の時、
3つの数全てがKの倍数である
Kが偶数の時、
3つの数全てがKの倍数である
3つの数全てのmod K がK/2である
を満たす数を数え上げて、その数を3乗（重複を許した3つの数の順列）
'''
n,k=map(int,input().split())
s=n//k
t=0
if k%2==0:
  t=(n+k//2)//k
print(s*s*s+t*t*t)

Solution (Python):
N,K=map(int,input().split())
ans=0
if K%2==0:
  A=[]
  B=[]
  for i in range(1,N+1):
    if i%K==0:
      A.append(i)
    elif i%K==K//2:
      B.append(i)
  ans=(len(A))**3+(len(B))**3
else:
  C=[]
  for i in range(1,N+1):
    if i%K==0:
      C.append(i)
  ans=(len(C))**3
print(ans)

Solution (Python):




def main():
    N, K = map(int, input().split())
    if K % 2 == 0:
        even = N // K
        odd = N // (K // 2) - even
        print(odd ** 3 + even ** 3)
    else:
        print((N // K) ** 3)


if __name__ == "__main__":
    main()