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: Time Limit Exceeded

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

p = 0

for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            x = a+b
            y = b+c
            z = c+a
            xa = x % k
            xb = y % k
            xc = z % k
            if xa == 0 and xb == 0 and xc == 0:
                p += 1
            else:
                pass
              
print( p )

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
b = a[0]//a[1]
if a[1] % 2 != 0:
  print(b**3)
else:
  if a[0]%a[1] >= a[1]//2:
    print(b**3 + (b+1)**3)
  else:
    print(2*b**3)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K):
    div0 = N // K
    divh = (N + (K // 2)) // K if K % 2 == 0 else 0
    import math
    print(div0 ** 3 + divh ** 3)


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    N, K = map(int, input().split())
    # A = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, K)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n, k = LI()
if k % 2 != 0:
    print((n // k) ** 3)
else:
    if n % k >= k // 2:
        print((n // k) ** 3 + (n // k + 1) ** 3)

    else:
        print((n // k) ** 3 + (n // k) ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
for a in range(1, n+1):
    mod = a % k
    temp_mod = (k-mod)%k
    #print(temp_mod)
    if (temp_mod*2) % k != 0:
        continue
    ans += num[temp_mod]**2
print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = pow(N // K, 3)
    if K % 2 == 0:
        ans += pow((N + K // 2) // K, 3)

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

    ans = 0
    for a in range(K):
        if 2 * (K - a) % K == 0:
            ans += R[a] * R[(K - a) % K] ** 2

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

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

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

    ans = 0
    for a in range(k):
        b = (k-a)%k
        if 2*b%k == 0: # b==cとしてbを2倍
            ans += R[a] * R[b] * R[b]

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

    ans = 0
    for a in range(K):
        b = (K - a) % K
        if 2 * b % K == 0:
            ans += R[a] * R[b] * R[b]

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = 0
    step = K if K % 2 else K // 2

    for a in range(step, N + 1, step):
        l = a // K + 1
        r = (N + a) // K
        if r >= l:
            ans += (r - l + 1) ** 2

    print(ans)
    return


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//2)//k)**3) + ((n//k)**3))

Submission status: Accepted

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

Submission status: Accepted

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

if K % 2 == 1:
    print((N // K) ** 3)
else:
    a = N // K
    t = K // 2
    b = (N - t) // K + 1
    print(a ** 3 + b ** 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 + 1) ** 3))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

# aは全探索
ans = 0 
for a in range(1, n+1):
    ra = a%k 
    rbc = k-ra
    if (2*rbc) % k == 0:
        ans += ((n-rbc)//k + 1)**2

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys 

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

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

#for a in range(1, n+1):
#    for b in range(a, n+1):
#        for c in range(b, n+1):
#            if((a+b)%k==0 and (b+c)%k==0 and (c+a)%k==0):
#                if(a!=b and b!=c and c!=a): cnt+=6
#                if(a==b and b==c and c==a): cnt+=1
#                else: cnt+=3

Submission status: Accepted

Solution code:
from math import ceil, floor
N,K=map(int, input().split())
if K % 2 == 1:
    ans = (floor(N/K) - ceil(1/K) + 1)**3
    print(ans)
else:
    ans = (floor(N/K - 1/2) - ceil(1/K - 1/2) + 1)**3
    ans += (floor(N/K) - ceil(1/K) + 1)**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:
  half=k//2
  if half>k:
    print(0)
  else:
    ans=0
    while half<=n:
      ans+=1
      half+=k
      
    a=n//k
    print(a**3+ans**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n, k = read_ints()
    if k % 2:
        print((n // k)** 3)
    else:
        print((n // k)** 3 + ((n + k // 2) // k)** 3)     

if __name__ == '__main__':
    Main()

Submission status: Accepted

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

if k ==1:
    print(n**3)

elif k ==2:
    m = n % 2
    o = n//2
    print((o+m)**3+o**3)

elif k % 2==1:
    x = n//k
    print(x**3)

else:
    x = n//k
    y = n//(k//2)
    print(x**3+(y-x)**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial  # , gcd
from bisect import bisect_left, bisect_right  # bisect_left(list, value)

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7


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


pl = lambda x: print(*x, sep="\n")

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

com = combinations

res = 0
if K % 2 == 0:
    res += len(range(0 + K // 2, N + 1, K)) ** 3
    res += len(range(K, N + 1, K)) ** 3
else:
    res += len(range(K, N + 1, K)) ** 3
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

#print(am)

ans = 0
for i in am:
  ans += i**3 
  
print(ans)

Submission status: Accepted

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

if k%2==1:
    cnt0=n//k

    print(cnt0**3)
else:
    cnt0=n//k
    cnt1=(n-k//2)//k+1 if n>=k//2 else 0
    ans=cnt0**3+cnt1**3
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

ans = 0
for am in range(0, k):
    bm = (k - am) % k
    cm = (k - am) % k
    if (bm + cm) % k == 0:
        ans += modk[am] * modk[bm] * modk[cm]
print(ans)

Submission status: Accepted

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

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

from collections import Counter
dic=Counter(s)

ans=0
for a in dic:
  if (2*a)%k==0:
    ans=ans+dic[a]*dic[(k-a)%k]*dic[(k-a)%k]
    
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
am_0=[]
am_k2=[]

if k%2==0:
  for i in range(1,n+1):
    if i%k==0:
      am_0.append(i)
    
    elif i%k==(k//2):
      am_k2.append(i)
  print(len(am_0)**3+len(am_k2)**3)
  
else:
  print(pow((n//k),3))

Submission status: Accepted

Solution code:
def main():
  N, K = [int(n) for n in input().split(" ")]

  mul_K = int(N/K)

  if K % 2 == 1:
    print(mul_K ** 3)
    return 0
  
  mul_K_half = int(2 * N/K)
  mul_K_half_but_K = mul_K_half - mul_K
  print(mul_K ** 3 + mul_K_half_but_K ** 3)
  return 0

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=[0]*k
ans=0
for i in range(1,n+1):
    l[i%k]+=1
for j in range(k):
    bj=(-j)%k
    cj=(-j)%k 
    if (bj+cj)%k==0:
        ans+=(l[j]*l[bj]*l[cj])
        
print(ans)

Submission status: Accepted

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

s = 0

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

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

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 == 1:
        a = N // K
        print(a * a * a)
        exit()
    else:
        a = N // K
        count = a * a * a
        b = (N+K//2)//K
        count+=b*b*b
        print(count)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(1, n + 1):
    if i % k == 0:
        mod_0 += 1
    elif i % k == (-i) % k:
        mod_harf += 1

res = mod_0 ** 3 + mod_harf ** 3
print(res)

Submission status: Accepted

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

if k%2 == 1: # kが奇数の場合
  x = 0
  for i in range(1,n+1):
    if i%k == 0: x += 1 # kで割り切れる値の数をカウント
  print(x**3) # 組み合わせ分増える
else: # kが偶数の場合
  x = 0
  for i in range(1, n+1):
    if i % k == 0: x += 1 # kで割り切れる値の数をカウント
  y = 0
  for i in range(1, n+1):
    if i % k == k//2: y += 1 # k//2で割り切れる値の数をカウント
  print(x**3 + y**3) # 組み合わせ分増える

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = pow(N // K, 3)
    if K % 2 == 0 and N >= K // 2:
        ans += pow((N - K // 2) // K + 1, 3)

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,k = inpm()

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
extra = [0]*K
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)

Submission status: Accepted

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

# 1以上N以下で、Kで割った余りが0,1,...,K-1となる個数
l = [0] * K
for i in range(1, N + 1):
    l[i % K] += 1

ans = 0

# aをKで割った余りは0,1,...,K-1
for ai in range(K):
    # bをKで割った余り...(a+b)%K==0から   cをKで割った余り...(a+c)%K==0から
    # ai = 0の時にK-aiがKとなって「余り」として不適なので%をかける
    bi = (K - ai) % K
    ci = (K - ai) % K
    # (b+c)%K==0を満たせば良い
    if (bi + ci) % K == 0:
        ans += l[ai] * l[bi] * l[ci]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = (int(T) for T in input().split())
Reminder = [0]*K
for NT in range(1,N+1):
    Reminder[NT%K] += 1
Count = 0
for RA in range(0,K):
    RB = (K-RA)%K
    RC = (K-RA)%K
    if (RB+RC)%K==0:
        Count += Reminder[RA]*Reminder[RB]*Reminder[RC]
print(Count)

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

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  # num[x] = Kで割ってx余る数が1以上N以下に何個あるか
ans = 0
for a in range(K):

    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K != 0:
        continue
    ans += num[a] * num[b] * num[c]
print(ans)

Submission status: Accepted

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

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

n = N // (K//2)
n_odd, n_even = (n+1)//2,n//2
print(n_odd**3+n_even**3)

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))
modZeroCount = N // K
modHalfCount = 0
if K % 2 == 0:
    modHalf = K // 2
    if N % K < modHalf:
        modHalfCount = modZeroCount
    else:
        modHalfCount = modZeroCount + 1
answer = modZeroCount ** 3 + modHalfCount ** 3
print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

ans = 0

num_multiple = n//k

ans += num_multiple**3

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

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:
#プログラミング日記   一寸先は闇が人生
# https://pyteyon.hatenablog.com/entry/2018/09/02/094228
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N,K = map(int, input().split())

# 偶数、奇数共に
# a,b,c mod 0,0,0 ⇒Kの倍数
multip_K =[i for i in range(K,N+1,K)]

#multip_Kから３つ選び並べる順列組み合わせ
le =len(multip_K)
ans_mod_0 =le **3

# 偶数のみ
# a,b,c mod K/2,K/2,K/2 
ans_mod_haf =0
if K%2 ==0:
    multip_haf =[i for i in range(1,N+1) if i %K ==K//2 ]
    le_haf =len(multip_haf)
    ans_mod_haf =le_haf **3

ans =ans_mod_0 +ans_mod_haf
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()

    # abc全てK//2か全て0のどちらか
    num_0 = N // K
    if K % 2 == 0:
        num_K_half = N // K + (1 if N % K >= K // 2 else 0)
    else:
        num_K_half = 0

    ans = num_0 ** 3 + num_K_half ** 3
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    e = sum(i%K!=0 and i*2%K==0 for i in range(1, N+1))
    z = sum(i%K==0 for i in range(1, N+1))
    return pow(e, 3) + pow(z, 3)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(N, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

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

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split())
    ans=0
    baisuu=n//k
    ans+=baisuu**3
    if k%2==0:
        if baisuu*k+k//2<=n:
            hanbun=baisuu+1
        else:
            hanbun=baisuu
        ans+=hanbun**3
    print(ans)
if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  if k%2==0:
    return (n//(k//2)-(n//k))**3+(n//k)**3
  return (n//k)**3

# main()
print(main())