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())
ans=0
if k>2*n:
  print(ans)
else:
  r=k
  for i in range(1,k):
    if 2*i%k==0:
      r=i
  amari=set()
  for i in range(1,(n-r)//r+1+1):
    if r*i%k in amari:
      continue
    else:
      amari.add(r*i%k)
      q=(n-r*i)//k+1
      ans+=q**3
  print(ans)

Submission status: Accepted

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


kcd=0
kcd_half=0
for i in range(1,n+1):
    if k&1 and i%k==0:
        kcd+=1
    elif not k&1:
        if i%k==0:
            kcd+=1
        if i%k==k//2:
            kcd_half+=1

print(kcd*kcd*kcd+kcd_half*kcd_half*kcd_half)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
ans = 0
N, K = [int(i) for i in input().split()]
x = 0
y = 0
for i in range(1, N+1):
    if i % K == 0:
        x += 1
    if K % 2 == 0 and i % K == (K//2):
        y += 1
print(x**3 + y**3)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,K=list(map(int,input().split()))
if K%2 == 0:
    A = list(range(K//2,N+1,K))
    B = list(range(K,N+1,K))
else:
    A = list(range(K,N+1,K))
    B = []
print(len(A)**3+len(B)**3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
rem0 = n // k
remhalf = (n // k + 1 if (n // k) * k + k // 2 <= n else n // k)
ans = rem0 ** 3 + (remhalf ** 3 if k % 2 == 0 else 0)
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:
n,k = map(int, raw_input().split(' '))
a,b = n / k,  n / k + (1 if 0 < k / 2 <= n % k else 0)
print a ** 3 + (b ** 3 if k % 2 == 0 else 0)

Submission status: Accepted

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

Submission status: Accepted

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

left = n % k
cc = [0] * k
for ii in range(k):
	cc[ii] += n / k
	if 0<ii <= left: cc[ii] += 1


r = 0
for ii,vv in enumerate(cc):
	if (2*ii) % k == 0:
		jj = (k - ii) % k
		r += vv * ((cc[jj]) ** 2) 
print r

Submission status: Accepted

Solution code:

import collections 
n,k = map(int, raw_input().split(' '))

left = n % k
cc = [0] * k
for ii in range(k):
	cc[ii] += n / k
	if 0<ii <= left:
		cc[ii] += 1


r = 0
for ii in range(len(cc)):
	if (- 2*ii) % k == 0:
		r += cc[ii] * ((cc[(k - ii) % k ]) ** 2) 

print r

Submission status: Accepted

Solution code:

import collections 
n,k = map(int, raw_input().split(' '))

cc=  collections.Counter()
left = n % k
for ii in range(k):
	cc[ii] += n / k
	if 0<ii <= left:
		cc[ii] += 1


r = 0
for ii in cc:
	if (- 2*ii) % k == 0:
		r += cc[ii] * ((cc[(k - ii) % k ]) ** 2) 

print r

Submission status: Accepted

Solution code:
import collections 
n,k = map(int, raw_input().split(' '))

cc=  collections.Counter()
for ii in range(1, n+1):
	cc[ii % k] +=1

r = 0
for ii in cc:
	if (- 2*ii) % k == 0:
		r += cc[ii] * ((cc[(k - ii) % k ]) ** 2) 
		#* cc[(k - ii) % k] 
print r

Submission status: Accepted

Solution code:

import collections 
n,k = map(int, raw_input().split(' '))

cc=  collections.Counter()
for ii in range(1, n+1):
	cc[ii % k] +=1

r = 0
for ii in cc:
	if 2*(k - ii) % k == 0:
		r += cc[ii] * ((cc[(k - ii) % k ]) ** 2) 
		#* cc[(k - ii) % k] 
print r

Submission status: Accepted

Solution code:

import collections 
n,k = map(int, raw_input().split(' '))

cc=  collections.Counter()
for ii in range(1, n+1):
	cc[ii % k] +=1

r = 0
for ii in cc:
	if ((k - ii) % k + (k - ii) % k) % k == 0:
		r += cc[ii] * cc[(k - ii) % k ] * cc[(k - ii) % k] 
print r

Submission status: Accepted

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

amari_0 = [] 
amari_Kw2 = []

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

if K%2 == 0:
    ans = pow(len(amari_0),3)
    ans += pow(len(amari_Kw2),3)
else:
    ans = pow(len(amari_0),3)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, K = list(map(int,input().split()))
if K % 2:  ans = (N // K) ** 3
else:
    ans = (N // K) ** 3
    cnt = 0
    temp = K // 2
    while(1):
        if temp > N:  break
        cnt += 1
        temp += K
    ans += cnt ** 3
print(ans)

Submission status: Accepted

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

if K%2==0:
    k=K//2
    k_1_list = list(range(k,N+1,k*2))
    k_2_list = list(range(K,N+1,K))
else:
    k=K
    k_1_list = []
    k_2_list = list(range(K,N+1,K))
    
# k_1_list,k_2_list

print(len(k_1_list)**3+len(k_2_list)**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    ans = 0
    if k%2==0:
        kouho1 = []
        kouho2 = []
        for i in range(1,n+1):
            if i%k==0:
                kouho1.append(i)
            elif i%k == k/2:
                kouho2.append(i)
        ans += len(kouho1)**3
        ans+= len(kouho2)**3
    else:
        kouho = []
        for i in range(1,n+1):
            if i%k==0:
                kouho.append(i)
        ans += len(kouho)**3

    print(ans)
main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
n0 = n//k
ans = pow(n0, 3)
if k%2 == 0:
    # a,b,c全ての余りがk/2のパターン
    r = n%k
    ans += pow(n0+int(n%k>=k//2), 3)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]

def nck(n, k, mod=10**9+7):
    bunbo = bunshi = 1
    for i in range(k):
        bunshi = (bunshi * (n-i)) % mod
        bunbo = (bunbo * (i+1)) % mod
    return (bunshi * pow(bunbo, mod-2, mod)) % mod

N,K=zz()
ans = 0
modK = 0
if (K % 2 == 0):
    mod0 = N//K
    ans += mod0**3
    a = (N + K//2)//K
    # print(a)
    ans+=a**3
else:
    mod0 = N // K
    ans=mod0**3
print(ans)

Submission status: Accepted

Solution code:


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

if __name__=="__main__":
    N,K = list(map(int, input().split()))
    solve()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
cnt1 = 0
cnt2 = 0
for i in range(1,n+1):
    if i%k == 0: cnt1 += 1
    if i%k == k//2: cnt2 += 1
ans = cnt1**3 if k%2 == 1 else cnt1**3+cnt2**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) // k) ** 3
print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, K = in_nn()

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

k_multi_cnt = n//k
ans = pow(k_multi_cnt,3)

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

print(ans)

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7

N,K = I()
if K%2 == 0:
    num = N//(K//2)     
    if num%2 == 0:
        num1 = num//2
        num2 = num//2
    else:
        num1 = num//2+1
        num2 = num//2
    print(num1**3+num2**3)
else:
    num = N//K
    print(num**3)

Submission status: Accepted

Solution code:
from collections import Counter

import numpy as np

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

mods = np.arange(1, N + 1) % K
counter = Counter(mods)

ans = 0
for a in counter.keys():
    if (a + a) % K == 0:
        ans += counter[a] ** 3

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,k = MI()

if k%2!=0:
    count = 0
    for i in range(1,n+1):
        if (i%k)==0:
            count += 1
    ans = count ** 3
    print(ans)
    exit()
else:
    count_1 = 0
    count_2 = 0
    for i in range(1,n+1):
        if (i%k)==0:
            count_1 += 1
        elif (i%k)==(k//2):
            count_2 += 1
    ans = count_1**3 + count_2**3
    print(ans)
    exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k%2 != 0:
  for i in range(1,n+1):
    if i%k == 0:
      R.append(i)
   
  print(len(R)**3)
else:
  for i in range(1,n+1):
    if i%k == 0:
      R.append(i)
    if i%k == k//2:
      Ro.append(i)
  print(len(R)**3 + len(Ro)**3)

Submission status: Accepted

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

if k%2 == 1:
    ans = (n//k)**3
else:
    ans = (n//k)**3 + ((n + k//2)//k)**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) // k) ** 3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
j=0
m=0
ans = 0
if k % 2 == 1:
    j= n//k
    #print('j',j)
    ans=j*j*j

else:
    j=n//k
    m=(n-k//2)//k+1
    #print('j',j,'m',m)
    ans=m*m*m+j*j*j
 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# import fractions

sys.setrecursionlimit(10000000)

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

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

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

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


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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, k = list(map(int, input().split()))
    if k % 2 == 0:
        n_k = sum([1 for i in range(1, n + 1) if i % k == 0])
        n_k2 = sum([1 for i in range(1, n + 1) if i % k == k // 2])
        print(n_k ** 3 + n_k2 ** 3)
    else:
        n_k = sum([1 for i in range(1, n + 1) if i % k == 0])
        print(n_k ** 3)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, K = MAP()

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, K = MAP()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
if k%2==0:
    l=k//2
    x=n//l
    if x%2==0:
        ans=2*(x//2)**3
    else:
        ans=(x//2)**3+(x//2+1)**3
else:
    ans=(n//k)**3
print(ans)

Submission status: Accepted

Solution code:
def solve(N,K):
    #方針
    #a mod K == a'(a' != 0)のとき
    #b mod K == c mod K == -a'
    #(b+c) mod K == -2a'
    #これで上手くいく(-2a' mod K == 0)のはKが偶数のときのみ
    if K % 2 != 0:
        return (N // K) ** 3
    else:
        return (N // K) ** 3 + ((N + K // 2) // K) ** 3

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

    print(solve(N,K))

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

Submission status: Accepted

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

ans = 0

ans += (N // K) ** 3

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


print(ans)

Submission status: Accepted

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

#n以下の整数で、a+b=kx b+c=ky c+a=kz
# a-b=k(x-y)


dic=[0]*k

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# (a,b,c)=(k/2,k/2,k/2)
if K%2==0:
    res += (1 + (N-K//2)//K)**3

# (a,b,c)=(k,k,k)
res += (N//K)**3

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

amaris = [N//K] * K
for i in range(N%K +1):
  amaris[i] += 1
amaris[0] -= 1

if K%2 == 1:
  print(amaris[0]**3)
else:
  print(amaris[0]**3 + amaris[K//2]**3)

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:
import math
n,k = map(int,input().split())
ans = 0
if k % 2 != 0:
	tmp = n//k
	ans += tmp**3
else:
	tmp = n//k
	ans += tmp**3
	tmp = n//(k//2) - tmp
	ans += tmp**3
print(ans)

Submission status: Accepted

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


def combination(n, r):
    ans = 1
    for i in range(r):
        ans *= n - i
    for i in range(r):
        ans //= i + 1
    return ans


# a+b % K == 0
# b+c % K == 0
# c+a % K == 0

# a が Kで割り切れる場合
#   -> bもcもKで割り切れる
#   -> a,b,cともにKの倍数
#   -> Kの倍数の個数(N//K) ** 3

# a がKで割れきれない場合
#   -> 同じくbもcもKで割り切れない
#   Q. Kが奇数の場合
#     -> それを満たす(a,b,c)の組み合わせはあり得ない
#   よってKは偶数
#     K=2のとき例より (a,b,c)=(1,1,1),(1,3,3),...
#     K=4のとき(a,b,c)=(2,2,2),(2,6,6),...
#     K=6のとき(a,b,c)=(3,3,3),(3,3,9),...
#   よりa % K == K/2である必要がある
#     a = x*K+K/2 (x=0以上の整数)

num_double = N//K
if K % 2 == 1:
    # Kが奇数の場合
    #  (1) (a,b,c)ともにKの倍数
    print(num_double ** 3)
else:
    # Kが偶数の場合,
    #  (1) (a,b,c)ともにKの倍数
    #  (2) (a,b,c)がいずれも Kで割った余りがK/2となる
    s = K // 2
    nums = [a for a in range(s, N+1, K)]
    n = len(nums)
    count = 0
    count += 6 * combination(n, 3)  # a,b,cがいずれも異なる値になるケースはnC3通り 順列は6倍
    count += 3 * n * (n-1)   # a,b,cのうち2つが同じ値になるケースはn(n-1)通り 順列は3倍
    count += n  # a,b,cが同じ値になるケースはn通り
    print(num_double ** 3 + count)

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:
# C - Triangular Relationship

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

# arr = a mod k の値のカウント
arr = [0] * K
for a in range(1, N+1):
    arr[a%K] += 1

# arr(a mod k)の値の範囲を探索する(0 〜 k-1)
# aの取りうる値の範囲ではない！
ans = 0
for a in range(K):
    b = -a % K
    c = -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 == 1:
    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 == 1:
  num = n // k
  print(num**3)
else:
  num = n // k
  num2 = (n+ int(k/2))//k
  print(num**3+num2**3)

Submission status: Accepted

Solution code:
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    """
    変数変換して格子点を数え上げようとして爆死。。。
    素直に問題文からa, b. cは2Kの倍数と分かるので、
    K:odd　→　a, b, cはKの倍数であり、かつこれは必要十分
    K:even →　a, b, cはK//2の倍数であり、必要十分にするには
    　　　　　 a, b, c = 0 (mod K) or a, b, c = K//2 (mod K)
    """
    if K % 2 != 0:
        val1 = (N // K) * (N // K - 1) * (N // K - 2)
        val2 = (N // K) * (N // K - 1) * 3
        val3 = N // K
        print(val1 + val2 + val3)
    else:
        val1 = (N // K) * (N // K - 1) * (N // K - 2) 
        val2 = (N // K) * (N // K - 1) * 3
        val3 = N // K
        # a, b, c = K//2 (mod K)の場合、N-K//2で=0 (mod K)として扱える。
        # ただしそのときa=0も許容される（本来それはK//2を意味するから）ことに注意
        N -= K // 2
        val4 = (N // K + 1) * (N // K) * (N // K - 1)
        val5 = (N // K + 1) * (N // K) * 3
        val6 = N // K + 1
        print(val1 + val2 + val3 + val4 + val5 + val6)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
num = {i%K:N//K for i in range(1, K+1)}
mod = N % K
for i in range(1, mod+1):
    num[i] += 1

ans = 0
for i in range(K):
    if (2*i) % K == 0:
        cnt = num[i]
        cnt *= num[(K-i)%K] * num[(K-i)%K]
        ans += cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# check
if K % 2 == 0:
    a = N // K
    b = (N + (K // 2)) // K
    print(a ** 3 + b ** 3)
else:
    a = N // K
    print(a ** 3)

Submission status: Accepted

Solution code:
N,K = (int(x) for x in input().split())
ans = 0
for a in range(1,N+1):
    am = a % K
    if (2*(K-am)) % K != 0:
        continue
    else:
        ans += ((N-(K-am))//K+1) ** 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
ans = 0
q, r = divmod(n, k)
for a in range(1, n+1):
    b = k - a%k
    c = k - b%k
    if (c + a)%k == 0:
        now = 1
        if 1 <= b%k <= r: now *= q+1
        else: now *= q
        if 1 <= c%k <= r: now *= q+1
        else: now *= q
        ans += now
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
# print('n,k',n,k)
# print('---')
ans = 0
q,r = divmod(n,k)
# print('q',q,'r',r)
for a in range(1, n+1):
    b = k - a%k
    c = k - b%k
    if (c+a)%k == 0:
        # print(a,b,c)
        now = 1
        if 1 <= b%k <= r: now *= q+1
        else: now *= q
        if 1 <= c%k <= r: now *= q+1
        else: now *= q
        ans += now

# print('ans',ans)
print(ans)