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:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, K = (int(_) for _ in input().split())
    ans = 0
    if K%2 ==0:
        d = N // K
        cnt = 0
        for i in range(1,N+1):
            if i % K == K/2: cnt+=1
        ans = d ** 3 + cnt ** 3
    else:
        d = N // K     
        ans = d ** 3
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#108_C
N,K=map(int,input().split())
x=N//K
Ans=x**3
if K%2==0:
    y=(2*N+K)//(2*K)
    Ans+=y**3
    
print(Ans)

Submission status: Accepted

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

Submission status: Accepted

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

if k%2==0:
    nsum=0
    for i in range(1,n+1):
        ia=i%k
        k2=k/2
        if ia==0:
            nb=(n-ia)//k
            nsum=nsum+nb**2
        elif ia==k2:
            nb=(n-ia)//k+1
            nsum=nsum+nb**2
        
else:
    nsum=0
    for i in range(1,n+1):
        ia=i%k
        if ia==0:
            nb=(n-ia)//k
            nsum=nsum+nb**2

print(nsum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a = 0
b = 0

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

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:
# 以下のいずれか
# :3つともKの倍数である
# :3つともKで割った余りがKの1/2である(Kが偶数)
n,k=map(int,input().split())
ans=0
if n>=k:
  c=n//k
  ans+=c**3
if k%2==0:
  if n>=k//2:
    c=(n-k//2)//k+1
    ans+=c**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)-n//k)**3)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    # 全探索する解法
    limit, divisor = map(int, input().split(" "))
    reminders = [0] * divisor
    answer = 0
    for i in range(1, limit + 1):
        reminders[i % divisor] += 1
    # 余りにより分類 -> 余り別に総計
    for i in range(0, divisor):
        others_reminder = (divisor - i) % divisor
        if not (2 * others_reminder) % divisor:
            answer += reminders[i % divisor] * (reminders[others_reminder]) ** 2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    # 整数問題で処理していく解法
    limit, divisor = map(int, input().split(" "))
    if divisor % 2:
        print((limit // divisor) ** 3)
    else:
        print((limit // divisor) ** 3 + ((limit + divisor // 2) // divisor) ** 3)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

# Case : a%K = b%K = c%K = 0
nk = N // K
ans = nk * nk * nk

# Case : a%K = b%K = c%K = K/2
if K%2 == 0:
    nk = (N+K//2) // K
    ans += nk*nk*nk
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = 0
b = 0
c = 0
kk = k // 2
for i in range(1,n+1):
    d = 2*i
    if k % 2 == 0 and i % k == kk:
        a += 1
    if i % k == 0:
        b += 1
    if (k % 2 == 0 and i % k == kk) and i % k == 0:
        c += 1

print(a**3 + b**3 - c**3)
# print(a,b,c)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ans = a ** 3
if K % 2 == 0:
  ans += b ** 3

print(ans)

Submission status: Accepted

Solution code:
import math
def wow(s):
    return s+3*s*(s-1)+s*(s-1)*(s-2)


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

s=n//k
if k%2!=0:
    if s==1:
        print(1)
    elif s==2:
        print(8)
    else:
        print(wow(s))
else:
    print(wow(s)+wow(((n-(k//2))//k)+1))

Submission status: Accepted

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

ans=0
ans+=pow(N//K,3)

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

Submission status: Accepted

Solution code:
n,k =map(int, input().split())
#連立方程式を解く
#m*k/2がn以下のkの倍数となる値を数える
#kが偶数の時、a,b,cをkで割った余りは0かk/2
#kが奇数の時、a,b,cをkで割った余りは0
ans=0
odd=0
even=0

#奇数の数
odd=n//k

#偶数の数
even=n//(k/2)-odd

if k%2==0:
  ans+=odd**3+even**3
else:
  ans+=odd**3

print(int(ans))

Submission status: Accepted

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

num=[0]*(max(N+1,K))
for i in range(1,N+1):
    num[i%K]+=1
#print(num)
ans=0
for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
      	#print(a)
        ans+=num[a]*num[b]*num[c]
        #print(a,b,c)
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
kk = 2*k
if k % 2:
    tmp = (n//k)**3
    print(tmp)
    exit()
kk = 0
k2 = 0
kkk = 0
for i in range(k//2,n+1):
    if i % k == 0:
        kk += 1
    if i % k == k//2:
        k2 += 1
    if i % k == 0 and i % k == k//2:
        kkk += 1
    # print(i, kk, k2, kkk)

print(kk**3 + k2**3 - kkk**3)

Submission status: Accepted

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

num = [0]*K
for n in range(1, N+1):
  num[n%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)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	n,k=map(int,input().split())
	
	cnt0=max(n//k,0)
	cnt2=max((n-k//2)//k+1,0)
	
	#print(cnt0,cnt2)
	
	if k%2:
		ans=cnt0**3
	else:
		ans=cnt0**3+cnt2**3
	
	print(ans)
	
	

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
mod = [0]*K
for i in range(1, N+1):
  mod[i%K] += 1
  
for a_modk in range(K)  :
  b_modk = (K - a_modk) % K
  c_modk = (K - a_modk) % K
  if (b_modk + c_modk) % K == 0:
    ans += mod[a_modk] * mod[b_modk] * mod[c_modk]
print(ans)

Submission status: Accepted

Solution code:
# 初等整数論
N, K = map(int, input().split())
if K%2 == 0:
  a = N//K
  b = (N+(K/2)) // K
  print(int(a*a*a + b*b*b))
else:
  a = N//K
  print(int(a*a*a))

Submission status: Accepted

Solution code:
import collections
N, K = [int(i) for i in input().split()]

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

Submission status: Accepted

Solution code:
import collections
N, K = [int(i) for i in input().split()]

# Kで割ってvalue余る数が1以上key以下にいくつあるか
d = collections.defaultdict(int)
for i in range(1, N + 1):
    d[i % K] += 1

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

Submission status: Accepted

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

ans = 0
mod = [0 for _ in range(K)]
for i in range(1, N+1):
    mod[i % K] += 1

for a_modk in range(K):
    b_modk = (K - a_modk) % K
    c_modk = (K - a_modk) % K
    if (b_modk + c_modk) % K == 0:
        ans += mod[a_modk] * mod[b_modk] * mod[c_modk]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,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 LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

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

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

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

  return ans

# main()
print(main())

Submission status: Accepted

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

# a + b = kx
# b + c = ky
# c + a = kz
# a = k(x-y+z)/2

div = n // k
# kが奇数のとき,(a,b,c)はそれぞれkで割った余りは0になる
if k % 2 == 1:
    print(div ** 3)
# kが偶数のとき,(1) + (2)を足したもの
# (1) (a,b,c)それぞれkで割った余りが0
# (2) k/2余る
else:
    if div * k + k/2 <= n:
        print(div**3 + (div+1)**3)
    else:
        print(2*(div**3))

Submission status: Accepted

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

ans = 0

if N == 1 and K != 1:
    print(0)
    exit()
if K % 2 == 0:
    # a, b, c が全て K の倍数
    cnt = N // K 
    ans = cnt ** 3
    K //= 2
    k = K
    # a, b, c が K//2 の奇数倍
    tmp = 1
    while 1:
        K += 2 * k
        if N < K:
            break
        tmp += 1
    ##print(cnt, tmp)
    ans += (tmp) ** 3
else:
    cnt = N // K
    ans = cnt ** 3

print(ans)

Submission status: Accepted

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

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

print(mm1**3+mm2**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = tuple(map(int, input().split()))
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)

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    N, K = [int(x) for x in input().split()]
    ans = 0
    if K & 1:
        print((N // K) ** 3)
    else:
        ans += (N // K) ** 3
        ans += ((N + K // 2) // K) ** 3
        print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

#割ってk//2な数の個数を求めるｗ
kosu=0
temp=k//2
while temp<=n:
  kosu+=1
  temp+=k

ans=0

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


print(ans)

Submission status: Accepted

Solution code:
import sys

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

def main():
    res = 0
    c = n // k
    res += c ** 3
    if k & 1:
        return res
    if n - k * c < k // 2:
        return res * 2
    else:
        return res + (c + 1) ** 3

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**9)
nCr = {}
def comb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = comb(n-1,r) + comb(n-1,r-1)
    return nCr[(n,r)]

def count(q):
    res = 0
    if q >= 1:
        res += comb(q, 1) * comb(3, 3)
    if q >= 2:
        res += comb(q, 2) * comb(2, 1) * comb(3, 2)
    if q >= 3:
        res += comb(q, 3) * comb(3, 1) * comb(2, 1)
    return res

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

def main():
    cnt1 = n // k
    res = count(cnt1)
    if k & 1:
        return res
    else:
        if n - k * cnt1 < k // 2:
            res *= 2
        else:
            cnt2 = cnt1 + 1
            res += count(cnt2)
        return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

print(ret**3+ret2**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+1)**3)

Submission status: Accepted

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import os
import sys

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = list(map(int, sys.stdin.buffer.readline().split()))

# 全部 K の倍数
ans = (N // K) ** 3
# 偶数ならKの半分でもOK
if K % 2 == 0:
    ans += math.ceil((N // (K // 2)) / 2) ** 3
print(int(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
num = [0] * K
for i in range(1, N + 1):
        num[i % K] += 1
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 != 0:
    w = n // k
    print(w**3)
else:
    w1 = n // k
    w2 = (n + (k//2)) // k
    print((w1 ** 3) + (w2 ** 3) )

Submission status: Accepted

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

def solve(N: int, K: int):
    if K%2 == 1:
        print((N//K)**3)
    else:
        a = 1+ (N-K//2)//K
        b = N//K
        print(a**3+b**3)
    return

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
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if K%2 != 0:
    # modK = 0となる1以上N以下のものの直積
    ans = (N//K)**3

else:
    # 上記に加えて、modK = K/2となるものの直積
    ans = (N//K)**3 + ((N-K//2)//K+1)**3
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

else:
    ans_1 = 1
    for i in range(3):
        ans_1 *= n // k
    ans_2 = 1
    for i in range(3):
        ans_2 *= len(list(range(int(k/2), n+1, k)))
    ans = ans_1 + ans_2
    print(ans)

Submission status: Accepted

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

#全てあまり0のパターン
x = N // K#あまりが0であるものの数
ans += x ** 3

#全てあまりが等しく、それがK/2に等しいパターン
if K % 2 == 0:
  y = (N - K //2) // K + 1#あまりがK/2であるものの数
  ans += y ** 3
  
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
if K % 2 == 1 :
    index = N // K
    ans = index**3
else :
    index = N // K
    ans = index**3
    k = K // 2
    indexa = (N // k) - index
    ans += indexa**3
print(ans)

Submission status: Accepted

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

count_a = 0

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

count_b = 0
count_list = []
if K % 2 == 0:
    for i in range(1, N+1):
        if i % K == K/2:
            count_list.append(i)
    count_b += len(count_list) ** 3

print(count_a**3 + count_b)

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    baisu = set()
    khalf = set()
    cnt = 0
    gusu = (K % 2 == 0)
    for x in range(1, N+1):
        if gusu and x % K == K // 2:
            khalf.add(x)
            continue
        if x % K != 0:
            continue
        baisu.add(x)
    cnt += len(baisu) ** 3
    cnt += len(khalf) ** 3
    print(cnt)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a % b)
def lcm(a,b):
  return a * b // gcd(a,b)
if k % 2 != 0:
  elements = n // k
  print(elements**3)
else:
  a = n // k
  b = (n + (k//2)) // k
  print(a**3 + b ** 3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
num = [0] * k
ans = 0
for i in range(1,n + 1):
  num[i%k] += 1
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 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()

# MOD Kでの値を集計
C = Counter()
for a in range(1, N+1):
    C[a%K] += 1

# aを決め打ちして全探索
ans = 0
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += C[a] * C[b] * C[c]
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
ans = 0
def A(x,N,K):
    p = N // K
    q = N % K
    if x == 0:
        x += K
    if x <= q:
        return p + 1
    else:
        return p
for a_mod in range(K):
    b_mod = (K - a_mod) % K
    c_mod = b_mod
    if (b_mod + c_mod) % K == 0:
        ans += A(a_mod,N,K) * A(b_mod,N,K) * A(c_mod,N,K)

print(ans)

Submission status: Accepted

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

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

    count = (n-b)//k
    if b != 0:
        count += 1
    ans += count**2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

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

#1~nについて考える
#1~nのうちi (modk) の個数の配列を作成
quotient = n//k
modk_cnt = [quotient for i in range(k)]
for i in range(n%k):
    modk_cnt[i+1]+=1

ret = modk_cnt[0]**3
if k%2==0:
    ret += modk_cnt[k//2]**3

print(ret)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
#a%kを決めればb%kとc%kが決まる
cnt=0
ans=0

for a_mod in range(k):
  if a_mod==0:
    b_mod,c_mod=0,0
  else:
    b_mod=k-a_mod
    c_mod=k-b_mod
    if c_mod!=k-a_mod:
      continue

  cnt_a=0
  for a in range(a_mod,n+1,k):
    if a!=0:
      cnt_a+=1
  ans+=cnt_a**3
print(ans)

Submission status: Accepted

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

list1 = []
listeven = []

for i in range(1,n+1):
    if i%k == 0: list1.append(i)
    elif i%k == k/2: listeven.append(i)

if k%2 != 0:
    print(len(list1)**3)

else:
    print(len(list1)**3 + len(listeven)**3)

Submission status: Accepted

Solution code:
def c_triangular_relationship():
    N, K = [int(i) for i in input().split()]

    count = [0] * K  # [x]: K で割って x 余る数が 1 以上 N 以下に何個あるか
    for i in range(1, N + 1):
        count[i % K] += 1

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

print(c_triangular_relationship())

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if k%2==1:
    x=int(n//k)
    print(x**3)
else:
    x=int(k/2)
    y=int((n-x)//k)+1  
    z=int(n//k)
    print(y**3+z**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+(1+(n-k//2)//k)**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x=n//k
#print(x)
if k%2==0:
    y=(n+k//2)//k
else:
    y=0
if x>=2:
    x=x+x*(x-1)*(x-2)+x*(x-1)*3
elif x==1:
    x=x+x*(x-1)*3
if y>=2:
    y=y+y*(y-1)*(y-2)+y*(y-1)*3
elif y==1:
    y=y+y*(y-1)*3
print(x+y)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from math import factorial

n,k = [int(x) for x in stdin.readline().rstrip().split()]
point = 0
point2 = 0
if k % 2 == 1:
    for i in range(1,n+1):
        if i%k == 0:
            point += 1
else:
    for i in range(1,n+1):
        if i % k == 0:
            point += 1
        elif i%k == k//2:
            point2 += 1

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

print(point**3+point2**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
answer=0
#条件はa,b,cが全てKの倍数か全てがmod(K/2)で後者はKが偶数の時のみ。
x_1=N//K#条件1　Kの倍数の数
if (N//K)*K+K//2>N:
  x_2=N//K
else:
  x_2=N//K+1
if K%2==0:
  answer=x_1**3+x_2**3
else:
  answer=x_1**3
print(answer)

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 = list(map(int, input().split()))

if k % 2 == 0:
    # 全部nの倍数
    x1 = int(n // k)
    # 全部nの倍数と半分
    x2 = int((n + k/2) // k)

    print(x1 ** 3 + x2 ** 3)

else:
    # 全部nの倍数
    x1 = int(n // k)
    print(x1 ** 3)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,K = inpl()


if K%2 == 0:
    Kdiv2 = K//2
    n1 = n2 = 0
    for i in range(1,N+1):
        if i%K == 0:
            n1 += 1
        elif i%Kdiv2 == 0:
            n2 += 1
    print(n1**3+n2**3)


else:
    n1 = n2 = 0
    for i in range(1,N+1):
        if i%K == 0:
            n1 += 1
    print(n1**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Kが奇数の時はa,b,cが全てKの倍数
# Kが偶数の時はa,b,cが全てmod(K)=0 となるか mod(K)=K/2となる
# なのでそれらを数え上げて3乗するだけ
N, K = list(map(int, input().split()))

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

Submission status: Accepted

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

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