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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,K = IL()



if K%2==0:
  n = N // (K//2)
  k = N // K
  n -= k
else:
  k = 0
  n = N // K

print(n**3+k**3)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc108


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

    rests = [x % K for x in range(1, N+1)]
    n_rests = [0 for _ in range(K)]
    
    for r in rests:
        n_rests[r] += 1
    
    ans = 0
    ans += n_rests[0]**3
    for r in range(1, K):
        ans += n_rests[r]**3 if r == K-r else 0
    
    return ans


print(main())

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())
count = 0

for i in range(1, n+1):
    if i*2 % k == 0:
        count += 1
        x = (n-i) // k
        count += x*6
        if x >= 2:
            count += 6 * (x*(x-1)//2)

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    ans = pow(N // K, 3)
    if K % 2 == 0:
        ans += pow((N+K//2)//K, 3)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, k = Is()
a = n//k
ans = a**3
if k % 2 != 0:
    print(ans)
    exit()

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

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
if k%2==1:
    count=0
    for i in range(1,n+1):
        if i%k==0:
            count+=1
    print(count**3)
else:
    countz,countk=0,0
    for i in range(1,n+1):
        if i%k==0:
            countz+=1
        elif i%k==(k//2):
            countk+=1
    print(countk**3+countz**3)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

# O(n)までOK a, b, cどれかを固定（ループ）させる
N, K = getNM()
# Kで割ってi余る数リスト
lista = [0] * K
ans = 0
for i in range(1, N + 1):
    lista[i % K] += 1
# 例えばN = 5, K = 3のとき1と４、2と5は同じものとして扱う
for a in range(K):
    # a（あまりがaであるもののどれか）に対応するb, cは
    # b == k - a(mod K)
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += lista[a] * lista[b] * lista[c]
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
#余りの分布
L = [0]*(K)

for i in range(1, N+1):
    L[i%K] += 1
ans = 0
for a in range(K):
    b = (K-a)%K
    c = (K-a)%K
    if (b+c)%K==0:
        ans = ans + L[a]*L[b]*L[c]
print(ans)

Submission status: Accepted

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

ans = (N//K) ** 3

if not K&1:
    ans += ( (N-K//2) // K + 1) ** 3
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = list(map(int, input().split(' ')))
    ans = (N // K)**3  # 0 mod K
    if K % 2 == 0:
        ans += ((N - K//2) // K + 1)**3  # K//2 mod K
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
div, rem = divmod(N, K)
print(div ** 3 + (not K & 1) * (div + (0 < K <= (rem << 1))) ** 3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
div, rem = divmod(N, K)
total = div ** 3
if not K & 1:
    total += (div + (0 < K <= (rem << 1))) ** 3
print(total)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
div, rem = divmod(N, K)
mods = [div + (0 < i <= rem) for i in range(K)]
total = mods[0] ** 3
if not K & 1:
    total += mods[K >> 1] ** 3
print(total)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
div, rem = divmod(N, K)
mods = [div + (0 < i <= rem) for i in range(K)]
total = 0
for mod_a in range(K):
    mod_b = (K - mod_a) % K
    mod_c = (K - mod_b) % K
    if mod_b == mod_c:
        total += mods[mod_a] * mods[mod_b] * mods[mod_c]
print(total)

Submission status: Accepted

Solution code:

inf = 10 ** 15
mod = 10 ** 9 + 7
n,k = map(int, input().split())
tmp = n//k
ans = (tmp*tmp*tmp)
if k % 2 == 1:
    print(ans)
if k % 2 == 0:
    tmp = (2*n+k)//(2*k)
    ans += (tmp*tmp*tmp)
    print(ans)

Submission status: Accepted

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

if k%2 == 1:
    cnts = []
    for i in range(1,n+1):
        if i % k == 0:
            cnts.append(i)
    print(len(cnts)**3)
else:
    k0 = 0
    k1 = 0
    for i in range(1,n+1):
        if i % k == 0:
            k0 += 1
        elif i %k == k//2:
            k1 += 1
    print(k0**3 + k1**3)

Submission status: Accepted

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

if k%2!=0:
	print((n//k)**3)
else:
	if (n//k)*k+(k//2)>n:
		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
# mod k == 0の数
m0 = n // k
ans += m0**3
# mod k == 0の数

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

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

# a+b+cは一定
# Kが奇数の時、全てKの倍数
# Kが偶数の時、全てKの倍数か、全てK//2 mod K
N, K = lr()
exact = N // K
answer = pow(exact, 3)
if K%2 == 0:
    half = N // (K//2) - exact
    answer += pow(half, 3)
print(answer)
# 29

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:
from itertools import product
N, K = list(map(int, input().split()))


ans = 0

count = N // K

ans += count ** 3

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

print(ans)

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, k = mi()
    if k % 2 == 1:
        mod_k = n // k
        # 順番変えたものは同一視するなら modkH3 = 3+modk-1C3 だけど
        print(mod_k ** 3)
    else:
        mod_k_0 = n // k
        mod_k_div2 = n // k + (n % k) // (k // 2)
        print(mod_k_0 ** 3 + mod_k_div2 ** 3)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=dict()
for i in range(k):
    d[i]=0
for i in range(1,n+1):
    d[i%k]+=1
#print(d)
if k%2!=0:
    print(d[0]*d[0]*d[0])
else:
    print(d[0]*d[0]*d[0]+d[k//2]*d[k//2]*d[k//2])

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

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


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

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

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

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

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

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

# 同じものを含む順列
def permutation_with_duplicates(L):

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

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

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

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

        return ret


# ここから書き始める
n, k = map(int, input().split())
num = [0 for i in range(k)]
for i in range(1, n + 1):
    num[i % k] += 1
ans = 0
for a in range(0, k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k == 0:
        ans += num[a] * num[b] * num[c]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def abc108_c():
  n, k = map(int, input().split())
  d, m = divmod(n, k)
  # n以下のkの倍数の個数、の3乗
  ans = d ** 3
  # %kがk/2になる数の個数、の3乗
  if k % 2 == 0:
    x = d
    if k // 2 <= m: x += 1
    ans += x ** 3
  print(ans)

abc108_c()

Submission status: Accepted

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

Submission status: Accepted

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

ans1=0
ans2=0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

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

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

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

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



if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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


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


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # 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())

zero = 0
even = 0

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

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

print(ans)

Submission status: Accepted

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

zero = 0
even = 0

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

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


print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)) // k + 1)**3
    print(ans)

Submission status: Accepted

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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
m0 = 0
mh = 0
ans = 0
for i in range(1,N+1):
    d = i%K
    if d == 0:
        m0+=1
    if d == K//2 and K % 2 == 0:
        mh +=1
print(m0**3 + mh**3)

Submission status: Accepted

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

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

ans = (n//k)**3

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# solution

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

Submission status: Accepted

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

if __name__ == '__main__':
  main()

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)