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 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    if K % 2 == 0:
        c1, c2 = 0, 0
        for i in range(1, N+1):
            if i % K == 0:
                c1 += 1
            if i % K == K // 2:
                c2 += 1
        print(c1 ** 3 + c2 ** 3)
    else:
        print((N // K) ** 3)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

else:
    print((N//K)**3)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 0
for a in range(1, n + 1):
    if (2 * a) % k == 0:
        x += 1

y = 0
for a in range(1, n + 1):
    if a % k == 0:
        y += 1

print((x - y) ** 3 + y ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

s = []
for a in range(1, n + 1):
    if (2 * a) % k == 0:
        s.append(a)

t = []
for a in range(1, n + 1):
    if a % k == 0:
        t.append(a)

print((len(s) - len(t)) ** 3 + len(t) ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

if K % 2 == 1: #Kが奇数
    count = N // K
    print (count ** 3)
else:
    count = N // K #Kの倍数の個数
    ans = count ** 3
    count = N // (K // 2) - N // K
    ans += count ** 3
    print (ans)

Submission status: Accepted

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

    count+= num + num*(num-1)*(num-2) + num*(num-1)*3
print(count)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

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

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

ans = 0
for v in range(1, K + 1):
    b = (K - v) % K
    c = (K - v) % K
    if (b + c) % K != 0:
        continue
    ans += m[v % K] * m[b] * m[c]
print(ans)

Submission status: Accepted

Solution code:
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/arc081/tasks/arc081_b
# D - Coloring Dominoes
"""
need to consider the case that ticket is not enough to lower everything
"""


def calc(num):
    return num**3


N = gi()
K = gi()

num = N // K
ans = calc(num)

if (K % 2 == 0):
    if N % K >= K // 2:
        num += 1
    ans += calc(num)

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

#a%K=A, b%K=B, c%K=C としたとき,
#A=B=C=0 か、
#A=B=C=K/2 (Kは偶数) のどちらが成り立つ

#N以下のKの倍数の数
kt=N//K

#A=B=C=0を満たす組の数
z=kt*kt*kt

#A=B=C=K/2 (Kは偶数) を満たす組の数
o=0
if K&1==0:
    an=kt+(1 if N%K>=K/2 else 0)
    o=an**3

print(z+o)

Submission status: Accepted

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

if (K % 2) == 1:
    count = N // K
    print(count**3)
else:
    count1 = N // K
    count2 = 0
    for i in range(N + 1):
        if (i % K) == (K / 2):
            count2 += 1
    # print(count1, count2)
    print(count1**3 + count2**3)

Submission status: Accepted

Solution code:
def examC():
    N, K = LI()
    a = N//K
    ans = a**3
    if K%2==0:
        b = (N + K//2)//K
        ans +=b**3
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Accepted

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

if k/2==k//2:
    p=n//(k//2)

    if p==0:
        print(0)
    elif p==1:
        print(1)
    elif p==2:
        print(2)
    elif p==3:
        print(9)
    elif p==4:
        print(16)
    else:
        m=16
        for i in range(5,p+1):
            m+=1+6*((-(-i//2))-1)+6*((-(-i//2))-1)*(-(-i//2)-2)//2
        print(m)
    
else:
    p=n//k

    if p==0:
        print(0)
    elif p==1:
        print(1)
    elif p==2:
        print(8)
    else:
        m=8
        for i in range(3,p+1):
            m+=1+6*(i-1)+6*(i-1)*(i-2)//2
        print(m)

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

even = n // k
odd = (n + k//2) // k

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

print(res)

# Sent from my iPhone

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
c = (n//k) ** 3
if k%2 == 0:
    c += ((n-(k//2))//k+1) ** 3
print(c)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
t = [0] * K
for i in range(1, N + 1): t[i % K] += 1
#print(t)
res = 0
for a in range(K):
  b = (K - a) % K
  c = (K - b) % K
  if (c + a) % K == 0:
    res += t[a] * t[b] * t[c]
print(res)

Submission status: Accepted

Solution code:
import math

nk = input().split()
n = int(nk[0])
k = int(nk[1])
res = 0

if k % 2 == 1:
    # a b c equiv 0 mod k
    res = int(math.pow(math.floor(n / k), 3))
else:
    mk0 = 0
    mkk2 = 0
    for i in range(1, n+1):
        if i % k == 0:
            mk0 += 1
        if i % k == (k / 2):
            mkk2 += 1
    res = int(math.pow(mk0, 3) + math.pow(mkk2, 3))

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    ls = []
    for i in range(1, n + 1):
        ls.append(i % k)
    h = 0
    j = 0
    for v in ls:
        if v == 0:
            j += 1
        if v * 2 == k:
            h += 1
    print(j ** 3 + h ** 3)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

    if K % 2 != 0:
        ans = (N // K)**3
    else:
        n = N // K
        if (n + 0.5) * K <= N:
            ans = (n + 1)**3 + n**3
        else:
            ans = 2 * n**3

    print(ans)


main()

Submission status: Accepted

Solution code:
import math
N, K = map(int,input().split())
ans = 0
ans += (N//K)**3

if K%2 == 0:
    cnt = 0
    for i in range(1,N+1):
        if i%K == int(K/2):
            cnt += 1
    ans += cnt**3
    #ans += (math.ceil(N/K))**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    c=0
    if 2*i%k==0:
        c+=1+(n+i)//k+(-1-i)//k
    #python3 a.pyprint(c)
    ans+=c**2
print(ans)

Submission status: Accepted

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

# a= -b = c = -a mod k

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
N,K = map(int,input().split())

if K%2 != 0:
    pattern = N//K
    print(pattern ** 3)
else:
    k = K // 2
    p1 = N//K
    p2 = N//k
    p3 = p2-p1
    print(p2**3 - 3*p1*p3*p3 - 3* p1*p1*p3)

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

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

ans = (N//K)**3

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

Submission status: Accepted

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

def solve_even(N: int, K: int):
    return pow((N - (K//2)) // K + 1, 3) + pow((N - K) // K + 1, 3)

def solve(N: int, K: int):
    return pow(N // K, 3) if K % 2 else solve_even(N, K)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    K = int(next(tokens))
    print(solve(N, K))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
#N以下の数でKの倍数の個数(mod K で0と等しいものの個数)
cntMod = N//K
#Kが奇数のときは3つ組として(0,0,0)しかとれない　ただしmod K
#Kが偶数のときは3つ組として(K/2,K/2,0)もとれる ただし　mod K
if K%2==0:
    if K*cntMod+K//2 <= N:
        cntMid = cntMod + 1
    else:
        cntMid = cntMod
else:
    cntMid = 0
print(cntMid**3+cntMod**3)

Submission status: Accepted

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

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

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

Submission status: Accepted

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = 0
for i in range(3):
    if i == 0:
        ans += count
        ans += count2
    elif i == 1:
        # 3C1*count*count-1
        ans += 3*count*(count-1)
        ans += 3*count2*(count2-1)
    else:
        ans += count*(count-1)*(count-2)
        ans += count2*(count2-1)*(count2-2)


print(ans)

Submission status: Accepted

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

# 1からNまでにmodKでiとなるものがいくつあるか数えておく。
num = [0 for _ in range(K)]
for i in range(1,N+1):
  num[i%K] += 1

ans = 0
# aを決め打ちすると、a+b=0modK,c+a=0modKよりb,cが定まる。
# それがb+c=0modKを満たすかチェックする。
for a in range(K):
  b = (K-(a%K))%K
  c = (K-(a%K))%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:
    knum = n // k
    print(knum ** 3)
else:
    knum = n // k
    kodd = (n + k // 2) // k
    print(knum ** 3 + kodd ** 3)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

# Kが偶数の場合, 全てKの倍数または全てK//2に倍数の両方考える必要あり
num = [0]*(K+1)  # 1以上N以下の整数で余りが0~K-1の個数をカウントする
for i in range(1, N+1):
    num[i % K] += 1  # i % K の取りうる値は0~K-1

ans = 0
for a in range(K+1):  # aに関して全探索を行う
    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())

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, input().split())
ans = (n//k)**3
if not k % 2: ans += ((n+k//2)//k)**3
print(ans)

Submission status: Accepted

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

ans = 0

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

for a in range(K+1):
    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:
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
num=[0]*(k+1)
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:continue
    cnt+=num[a]*num[b]*num[c]
    
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

import sys
def input():
	return sys.stdin.readline().strip()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

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

Submission status: Accepted

Solution code:
[n,k]=[int(x) for x 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:
N,K=map(int,input().split())
if K%2==1:
    s=N//K
    print(s**3)
    exit()
k=K//2
s=N//k
num=0
if s%2==0:
    print((s**3)//4)
    exit()
t=((s//2+1)**2)*(s//2+1)
u=((s//2)**2)*(s//2)
print(t+u)

Submission status: Accepted

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


if __name__ == '__main__':
    func()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC102C
import sys

#n= int(input())
tmp = input().split()
n,k = list(map(lambda a: int(a), tmp))

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

Submission status: Accepted

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

k = []
half_k = []
for i in range(1,N+1):
    if(i%K == 0):
        k.append(i)
    elif(i%(K/2) == 0):
        half_k.append(i)

if(K%2 == 0):
    print((len(k) ** 3) + (len(half_k) ** 3))
else:
    print(len(k) ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

k = []
half_k = []
for i in range(1,N+1):
    if(i%K == 0):
        k.append(i)
    elif(i%(K/2) == 0):
        half_k.append(i)

if(K%2 == 0):
    print((len(k) ** 3) + (len(half_k) ** 3))
else:
    print(len(k) ** 3)

Submission status: Accepted

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

    if K&1: # Kが奇数
        tmp = N//K
        print(tmp**3)
    else:   # Kが偶数
        tmp = N//K
        tmp2 = tmp
        if N%K >= K//2:
            tmp2 += 1
        print(tmp**3 + tmp2**3)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
count = 0
i = 1
zero = 0
rem = 0
if k % 2 == 0:
    while i <= n:
        if i % k == 0:
            zero += 1
        elif i % int(k/2) == 0:
            rem += 1
        i += 1
    print(zero ** 3 + rem ** 3)
else:
    while i <= n :
        if i % k == 0:
            count += 1
        i += 1
    print(count ** 3)

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:
n, k = map(int, input().split())
tmp1 = n // k

if k % 2 == 0:
    tmp2 = (n + k//2) // k
else:
    tmp2 = 0

ans = tmp1 ** 3 + tmp2 ** 3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

ans = 0
cnt = 0
for i in range(K, N+1, K):
    cnt += 1
ans += pow(cnt, 3)

if K % 2 == 0:
    cnt = 0
    for i in range(K//2, N+1, K):
        cnt += 1
    ans += pow(cnt, 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:
N, K = [int(v) for v in input().split()]

kcnt = [0] * K

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

ans = 0
for a in range(1, K + 1):  # aを固定
    b = K - (a % K)
    c = K - (a % K)
    if (a + b) % K == 0 and (a + c) % K == 0 and (b + c) % K == 0:
        ans += kcnt[a%K] * kcnt[b%K] * kcnt[c%K]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if K%2 == 1:
	count3 = N//K
	ans = count3 ** 3

print(ans)

Submission status: Accepted

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

"""
2(a+b+c) = nK <= 6N
n=1,2,......,6N//K

a+b=iK-c<=2
2N>=iK-c

a+c=iK
a+b=jK
b-c=XK Xは整数
b+c=kK kは自然数
2b=(X+k)K 
b=X'K/2
→K=2a：bはa刻み
→K=2a-1：bはK刻み
"""


# max_n = (2*N)//K
# count = 0
# anslist = []
# for sum_ab in range(K, 2*N + 1, K):
#     print(("a+b", sum_ab))
#     min_a = sum_ab - N if sum_ab - N >= 1 else 1

#     for a in range(min_a, min(sum_ab, N+1)):
#         b = sum_ab - a
#         if (a - b) % K != 0:
#             continue
#         if b < 1 or b > N:
#             break
#         lower = min(a, b)
#         for c in range(1, N+1):
#             if (lower + c) % K == 0:
#                 # print((a, b, c))
#                 anslist.append([a, b, c])
#                 count += 1
# anslist.sort(key=lambda x: x[0])
# print(anslist)
# print(count)

if K % 2 == 0:
    kizami = K // 2
    max_kizami = N // kizami
    pa1 = max_kizami // 2
    pa2 = max_kizami - pa1
    print(pa1**3+pa2**3)
else:
    kizami = K
    max_kizami = N // kizami
    print(max_kizami**3)

"""偶数の場合
a+b=K max_kizami通り
    kizami kizami [kizami,kizami+K,...]
a+b=2K 2max_kizami　+　N//K通り
    1kizami 3kizami [kizami,kizami+K,...]
    2kizami 2kizami [2kizami,4kizami,...]
    3kizami 1kizami [kizami,kizami+K,...]


a+b=2(N//K)K
    max_kizami*kizami max_kizami*kizami [kizami,...]
"""
"""奇数の場合
K K [K,2K,...]

2K K []
K 2K []

3K K []
2K 2K []
K 3K []



max_kizami
"""

Submission status: Accepted

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

x, y = 0, 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:
n,k = map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ARC102C - Triangular Relationship (ABC108C)
def main():
    N, K = list(map(int, input().rstrip().split()))
    a = N // K
    if K % 2 != 0:  # K: odd
        print(a ** 3)
    else:  # K: even
        b = (N + K // 2) // K
        print(a ** 3 + b ** 3)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


cc = N//K
res = cc*cc*cc
if K%2 == 0 and N>=K/2:
    cc = (N-K/2)//K+1
    res+= cc*cc*cc

print(int(res))

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())
ans = 0
b, c = 0, 0
amari = [0] * (K+1)

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

n_set = 0
if K % 2 == 0:
  if N >= K/2:
  	n_modhalf = (N - K/2) // K + 1
  	n_set += n_modhalf ** 3
  
n_modK = N // K
n_set += n_modK ** 3

print(int(n_set))

Submission status: Accepted

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

Submission status: Accepted

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

li=[0]*K
for i in range(1,N+1):
  if (i*2)%K==0:
    li[i%K]+=1
print ( sum( [ v**3 for v in li ] ) )

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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