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

q = N//K
ans = q*q*q
if K % 2 == 1:
    print(ans)
else:
    p = (N+K//2)//K
    ans += p*p*p
    print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
ans = (N//K)**3

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

print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = (N // K) ** 3
    if K % 2 == 0:
        halfK = 0
        for i in range(1, N + 1):
            if i % K == K // 2: halfK += 1
        ans += (halfK) ** 3
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

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:
# ARC102 C
N, K = list(map(int, input().split()))
ans = 0
list_n = [0]*K

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

for a in range(K):
    b = (K - a) % K
    c = b
    if (b + c) % K == 0:
        ans += list_n[a] * list_n[b] * list_n[c]
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:
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())

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = n // k
b = (n + k//2) // k

if k % 2 == 0:
    print(a**3+b**3)
else:
    print(a**3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
list_N = [0]*k
for num in range(1, n+1):
    m = num % k
    list_N[m] += 1

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

print(ans)

Submission status: Accepted

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

if k % 2 == 1:
    p = n // k
    ans += pow(p, 3)
else:
    p = n//k
    q = (n + (k//2))//k
    ans += pow(p, 3) + pow(q, 3)

print(ans)

Submission status: Accepted

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

if k % 2 == 0:
    step = k // 2
    a = step
else:
    step = k
    a = step

ans = 0

while a <= n:
    b_num = c_num = (n+a)//k - a//k
    ans += b_num * c_num

    a += step

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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
result = a**3 + b**3
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
div = []
div2 =[]

for i in range(1,N+1):
    if (i%K == 0):
        div.append(i)
    elif (2*i%K == 0):
        div2.append(i)
    else :
        continue
l1 = len(div)
l2 = len(div2)
print(l2*l2*l2 + l1*l1*l1)

Submission status: Accepted

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

result=0

if K%2==1:
    #全てKの倍数でないといけない
    result=(N//K)**3
else:
    #全てKの倍数
    result=(N//K)**3

    #またはすべて余りがk/2でなければならない
    if (N//K)*K+K/2<=N:
        result+=(N//K+1)**3
    else:
        result+=(N//K)**3

print(result)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,K = map(int,input().split())
if K % 2 == 1:
    x = N // K
    print(x**3)
else:
    k = K // 2
    x = N // k
    if x % 2 == 0:
        y = x // 2
        print(2*(y**3))
    else:
        y = x // 2
        print(y**3+(y+1)**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 奇数の時
# a，b，cはkの倍数
# kが偶数
# a, b, cがkの倍数
#　もしくは，全てk/2の倍数

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

if K % 2 != 0:
    n = N // K 
    print(n ** 3)

else:
    n = N // K
    half_n = N // (K//2)
    print(n ** 3 + (half_n - n)** 3)

Submission status: Accepted

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

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

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:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    if k%2==0:
        print((n//k)**3+((n+k//2)//k)**3)
    else:
        print((n//k)**3)
    
            

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# print('N:{}, K:{}'.format(N, K))

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc102/tasks/arc102_a

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

dp = [0] * k

for i in range(1, n + 1):
    m = i % k
    dp[m] += 1
ans = dp[0] ** 3
if k % 2 == 0:
    ans += dp[k // 2] ** 3
print(ans)

Submission status: Accepted

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

if K%2!=0:
  p=N//K
  ans+= p**3
else:
  z=K//2
  a=(N-z)//K+1
  ans += a**3
  p=N//K
  ans+= p**3

print(ans)

Submission status: Accepted

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

if K%2!=0:
  p=N//K
  ans+= p**3
else:
  z=K//2
  a=(N-z)//K+1
  ans += a**3
  p=N//K
  ans+= p**3
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem C - Trianglar Relationship

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

# initialization
nums = [0]*K
for i in range(1, N+1):
    nums[i%K] += 1
ans = 0

# count
for a in range(0, K):
    b = (K - a) % K # 余りがどうなる数になるべきか
    c = (K - a) % K
    if not (b+c)%K==0:
        continue
    ans += nums[a] * nums[b] * nums[c]

# output
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, read().split())
x, y = 0, 0
for i in range(1, n + 1):
    if i % k == 0:
        x += 1
    elif i * 2 % k == 0:
        y += 1
print(x ** 3 + y ** 3)

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:
def main():
    N, K = (int(i) for i in input().split())
    c0 = 0
    c1 = 0
    for num in range(1, N+1):
        if num % K == 0:
            c0 += 1
        elif K % 2 == 0 and num % K == K//2:
            c1 += 1
    print(c0*c0*c0 + c1*c1*c1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    c0 = 0
    c1 = 0
    for num in range(1, N+1):
        if num % K == 0:
            c0 += 1
        elif K % 2 == 0 and num % K == K//2:
            c1 += 1
    print(pow(c0, 3) + pow(c1, 3))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    cnt = 0
    for i in range(1, 2*10**5+1):
        if K*i <= N:
            cnt += 1
        else:
            break
    addcnt = 0
    if K % 2 == 0:
        for i in range(1, 2*10**5+1, 2):
            if (K//2)*i <= N:
                addcnt += 1
            else:
                break
    ans = cnt**3 + addcnt**3
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
#1~NのKで割ったあまり
ks=0
k2s=0
for i in range(1,N+1):
    if K%2==0:
        if i%K==0:
            ks+=1
        elif i%(K//2)==0:
            k2s+=1
    else:
        if i%K==0:
            ks+=1
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


ans=0
if ks>=1:
    ans+=cmb(ks,1)
if ks>=2:
    ans+=cmb(ks,2)*6
if ks>=3:
    ans+=cmb(ks,3)*6
#print(ks,k2s)
if k2s>=1:
    ans+=cmb(k2s,1)
if k2s>=2:
    ans+=cmb(k2s,2)*6
if k2s>=3:
    ans+=cmb(k2s,3)*6
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N,K=map(int, input().split())
    z=h=0
    for i in range(1,N+1):
        if i%K==0:
            z+=1
        elif K&1==0 and i%K==K>>1:
            h+=1
    ans=z**3
    ans+=h**3
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = {}
q, r = divmod(n, k)
if r == 0:
    for i in range(k):
        d[i] = q
else:
    for i in range(k):
        if i == 0:
            d[i] = q
        elif 1 <= i <= r:
            d[i] = q+1
        else:
            d[i] = q
#print(d)
ans = 0
if k%2 != 0:
    ans = d[0]**3
else:
    ans = d[0]**3+d[k//2]**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if K == 1:
    print(N**3)
    exit()

ans = 0
for k in range(K):
    if (k * 2) % K != 0:
        continue
    M = (N // K) - (1 if k == 0 else 0)
    if N % K >= k:
        M += 1
    ans += M**3
print(ans)

Submission status: Accepted

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

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

else:
    tmp = N // K
    ans = tmp ** 3

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

    print (ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    r = [0 for _ in range(k)]
    for i in range(1, n + 1):
        r[i % k] += 1
    answer = 0
    for i in range(k):
        if 2 * (k - i) % k == 0:
            answer += r[i] * (r[k - i if i > 0 else 0] ** 2)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for a in range(1,n+1):
  m=(k-a-1)%k+1
  if (m+m)%k!=0:continue
  ans+=((n-m+k)//k)*((n-m+k)//k)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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


print(ans)

Submission status: Accepted

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

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

if K%2 != 0:
  ans = odd_count**3
else:
  ans = odd_count**3 + even_count**3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
u1=N//K
u2=N%K
ans=u1**3

A=[u1]*K
for i in range(u2):
    A[i+1]+=1
if K%2==0:
    ans+=A[K//2]**3
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if K % 2:
    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())
mods=[0]*k
mods[0]=n//k
for i in range(1,k):
    mods[i]=(n-i)//k+1
# print(mods)
ans=0

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

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    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(0, 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()

Submission status: Accepted

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

Submission status: Accepted

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

ans = pow(mod_0, 3) + pow(mod_K2, 3)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = (n // k) ** 3

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

    ans += temp ** 3

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, read().split())
memo = (n // k) ** 3
if k % 2 == 0:
    memo += ((n + k // 2) // k) ** 3
print(memo)

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def count_k():
    return (N // K) ** 3

def count_khalf():
    if K % 2 == 1:
        return 0
    b = N // K
    if N % K >= K // 2:
        b += 1
    return b ** 3


print(count_k() + count_khalf())

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

def solve(N,K):
    ans = (N//K)**3
    if K%2==0:
        ans += (N//(K//2)-N//K)**3
    return ans

print(solve(N,K))

Submission status: Accepted

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

if k % 2:
    print(n_mod0**3)
else:
    n_modk2 = (n+(k//2))//k
    print(n_mod0**3 + n_modk2**3)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,k = tuple([int(t)for t in input().split()])

    if k%2==0:
        t = n//k#kの倍数
        s = n//(k//2)-t#k//2の倍数でkの倍数でない数
        ans = t**3+s**3
        print(ans)
    else:
        ans = (n//k)**3
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N, K = mi()

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N, K = mi()
    
cnt_n = 0
ini_n = K
#while ini_n <= N:
    #cnt_n += 1
    #ini_n += K
cnt_n = N // K

ans = cnt_n ** 3

if K % 2 == 0:
    ini_k = K // 2
    '''
    cnt_k = 0
    while ini_k <= N:
        cnt_k += 1
        ini_k += K
    ans += cnt_k ** 3
    '''
    if N >= ini_k:
        ans += ((N - ini_k) // K + 1)**3

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N, K = mi()
    
cnt_n = 0
ini_n = K
while ini_n <= N:
    cnt_n += 1
    ini_n += K

ans = cnt_n ** 3

if K % 2 == 0:
    ini_k = K // 2
    cnt_k = 0
    while ini_k <= N:
        cnt_k += 1
        ini_k += K
    ans += cnt_k ** 3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans1**3 + ans2**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
from functools import reduce
from operator import mul
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？


n,k=mii()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, K = MI()
    a = []
    cur = K
    half = []
    zero = []

    dic = defaultdict(int)

    for i in range(1, N+1):
        if K % 2 == 1 and i % K == 0:
            zero.append(i)
        if K % 2 == 0 and i % K == K//2:
            half.append(i)
        if K % 2 == 0 and i % K == 0:
            zero.append(i)

    a = len(zero)
    b = len(half)

    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 not(K & 1):
    ans += ((N+(K//2))//K)**3
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

"""
Kが奇数なら, a=b=c=0(mod K)のみ
Kが偶数なら, a=b=c=K/2(mod K)「も」
"""

# n以下のmod Kがrの数の個数
def f(r):
    if r == 0: r = k
    return len(range(r, n + 1, k))

res = 0

# = 0
res += f(0) ** 3

# = k / 2
if k % 2 == 0:
    res += f(k // 2) ** 3

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

if k%2==0:
    #偶数の時
    amari1=n//k
    amari2=n//(k-k//2)-amari1
    ans=amari1**3+amari2**3
else:
    amari=n//k
    ans=amari**3
print(ans)

Submission status: Accepted

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

# 1
n = N // K
ret = n ** 3

# 2
if not K % 2:
    m = K // 2
    n = len(list(range(m, N+1, K)))
    ret += n ** 3

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
N, K = map(int, input().split())
ans = (N // K)**3
if K % 2 == 0:
  m = K // 2
  cnt = 0
  i = m
  while i <= N:
    i += K
    cnt += 1
  ans += cnt**3
print(ans)

Submission status: Accepted

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

s = n // k
a = n % k
h = 0

if k % 2 == 0 and a >= k/2:
    h = s+1
elif k % 2 == 0:
    h = s

print(s**3 + h**3)

Submission status: Accepted

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

if K % 2 == 0:
    ele1 = N // K
    ele2 = (N+K/2) // K
else:
    ele1 = N // K
    ele2 = 0

print(int(ele1**3 +ele2**3))

Submission status: Accepted

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

Submission status: Accepted

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


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


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N, K = read_values()
    res = 0
    P = K // 2 if K % 2 == 0 else K
    for a in range(P, N + 1, P):
        k = a // K + 1
        l = (N + a) // K
        res += (l - k + 1) ** 2

    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

#Kが奇数の場合、N mod K = 0を満たす数の3乗が解
if K % 2 == 1:
    print((N // K) ** 3)

#Kが偶数の場合、Kで割って0あまるものの個数とK / 2あまるものの個数の3乗が解
else:
    K2 = K // 2
    #Kで割ってK / 2余る個数を算出
    half = (N // K2 - N // K)
    print(half ** 3 + (N // K) ** 3)

Submission status: Accepted

Solution code:
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    N, K = MI()
    num_factor_K = N // K
    ret = num_factor_K ** 3
    
    if K % 2 == 0:
        num_factor_half_K = N // K
        if N % K >= K // 2:
            num_factor_half_K += 1
        ret += num_factor_half_K ** 3
        
    print(ret)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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