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

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

odd = n // k
even1 = n // k
even2 = (n + int(k/2)) // k

if k % 2 == 0:
    print(even1 ** 3 + even2 ** 3)
else:
    print(odd ** 3)

Submission status: Accepted

Solution code:
n,k= map(int,input().split())
rclass = [0]*(k)
for i in range(k):
    rclass[i] = int(n/k)
if n%k  != 0:
    for i in range(1,n%k+1):
        rclass[i] += 1
import math
def Comb(a,b):
    if a>= b:
        return int(math.factorial(a)/(math.factorial(b)*math.factorial(a-b)))
    else:
        return 0
def ans(lis,inte):
    return max(0,lis[inte])*max(0,lis[inte]-1)*max(0,lis[inte]-2)+Comb(lis[inte],2)*6+lis[inte]
print(ans(rclass,0) if k%2 == 1 else ans(rclass,int(k/2))+ans(rclass,0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N, K = map(int, input().split())
a = []
for i in range(1, N+1):
    a.append(i%K)
b = Counter(a)
ans = 0
for x in b:
    if x == 0:
        ans += b[x]**3
        continue
    if K%2 == 0 and x == K//2:
        ans += b[K//2]**3
print(ans)

Submission status: Accepted

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

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

counter1 = 0
counter2 = 0
for i in range(1, n+1):
    if i%k == 0:
        counter1 += 1
    elif i%k == k//2:
        counter2 += 1

print(counter1**3 + counter2**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
if k % 2 == 1:
    a = n // k
    print(a ** 3)
else:
    a = n // k
    t = a ** 3
    a1 = int(k/2)
    b1 = k - a1
    if n % k >= a1:
        s0 = (n // k) + 1
    else:
        s0 = n // k
    if n % k >= b1:
        s1 = (n // k) + 1
    else:
        s1 = n // k
    s = (s0 ** 2) * s1
    print(s + t)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
from functools import reduce
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)


N, K = MI()
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 = (N//K) ** 3
if K % 2 == 0:
    ans += ((N+K//2)//K)**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, factorial, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N, K = 0, 0


def set_inputs():
    global N, K
    N, K = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    sum_abc = itertools.dropwhile(
        lambda x: x < 3,
        itertools.takewhile(
            lambda x: x <= 3 * N,
            itertools.count(2 * K, K)
        )
    )
    ans = 0
    if K % 2 == 0:
        # a + b + c = (l + m + n) * (K // 2)
        # a, b, c >= 1
        x = N // K
        y = N // (K // 2) - x
        ans = x ** 3 + y ** 3
    else:
        # 2 * (a + b + c) = (l + m + n) * K
        x = N // K
        ans = x ** 3
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if K %2 == 0:
    c = 0 #(純粋な倍数)
    d = 0 #(二倍すれば倍数)
    for i in range(1,N +1):
        if i %K == 0:
            c+=1
        elif (i*2) %K ==0:
            d +=1
    print(c ** 3 + d ** 3)
else:
    l = N // K
    print(l ** 3)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
if K % 2 == 0:
    K_unit1 = int(N//K)
    K_half = K//2
    N_khalf = N-K_half
    K_unit2 = 1 + int(N_khalf//K)
    K1 = K_unit1 ** 3
    K2 = K_unit2 ** 3
    out = K1 + K2
else:
    K_unit1 = int(N/K)
    out = K_unit1 ** 3

print("{0}".format(out))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))
def f(n):
    return n*(n-1)*(n-2) + n*(n-1)*3 + n
if K%2:
    n = N//K
    print(f(n))
else:
    n = N//(K//2)
    a = n//2
    b = (n+1)//2
    print(f(a)+f(b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# not solved only by mysql

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

if K % 2 != 0:
    even = len([n for n in range(1,N + 1) if n % K == 0])
    print(even ** 3)
else:
    ks = len([n for n in range(1, N + 1) if n % K == 0])
    ks_half = len([n for n in range(1, N + 1) if n % K == K // 2 ])
    print(ks_half**3 + ks ** 3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
def search(n,k):
    buf = [[],[]]
    for i in range(1,n+1):
        if i % k == 0:
            buf[0].append(i)
        elif k % 2 == 0 and i % k == k // 2:
            buf[1].append(i)
    return buf
def countans(l):
    length = len(l)
    if length == 1:
        return 1
    elif length == 2:
        return 2 + 2*1*3
    else:
        return length + length*(length-1)*3 + length*(length-1)*(length-2)
buf = search(n,k)
print(countans(buf[0])+countans(buf[1]))

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

Submission status: Accepted

Solution code:
n, k = [int(item) for item in 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:
#!/usr/bin/env python3
import sys
 
 
def solve(N: int, K: int):
    count = 0
 
    if K % 2 == 0:
        count += (N//K)**3
        # a,b,c == 0 mod K//2
        count += (N//(K//2) - N//K)**3
    else:
        count += (N//K)**3
    print(count)
    return
 
 
def main():
    N,K= map(int,input().split())
    # N = int(next(tokens))  # type: int
    # K = int(next(tokens))  # type: int
    solve(N, K)
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(N: int, K: int):
    count = 0

    if K % 2 == 0:
        count += (N//K)**3
        # a,b,c == 0 mod K//2
        count += (N//(K//2) - N//K)**3
    else:
        count += (N//K)**3
    print(count)
    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() )
ans = int((n//k)**3)

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

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product # 全探索
from bisect import bisect_left, bisect_right

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

N, K = s_inpl()

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

print(ans)

Submission status: Accepted

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

if K%2==0: #余りK/2と0の２パターン
    rem_0=N//K
    rem_K2=(N//(K/2))-rem_0
    answer=int(rem_0**3+rem_K2**3)
else: #余りが0のみのパターン
    answer=int((N//K)**3)

print(answer)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
N = a[0]
K = a[1]
cnt = (N // K) ** 3
if K % 2 == 0:
    mod = K // 2 
    cnt += ((N - mod) // K + 1) ** 3
print(str(cnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    print(n*800-200*(n//15))

#B
def B():
    k = I()
    ans = 0
    for i in range(1,k):
        for j in range(i+1,k+1):
            if (i%2)^(j%2):
                ans += 1
    print(ans)

#C
def C():
    x,t = LI()
    print(max(0,x-t))

#D
def D():
    n = I()
    ans = 1
    for i in range(1,n+1):
        ans *= i
        ans %= mod
    print(ans)

#E
def E():
    x,y,s,t = LI()
    return

#F
def F():
    n = I()
    x = LI()
    a = sorted(x)
    for i in range(n):
        j = bisect.bisect_left(a,x[i])
        if j >= n//2:
            print(a[n//2-1])
        else:
            print(a[n//2])

#G
def G():
    n,m = LI()
    if m <= 2*n:print(m//2)
    else:
        ans = n
        m -= 2*n
        ans += m//4
        print(ans)

#H
def H():
    n,k = LI()
    if k%2:
        l = n//k
        print(l**3)
    else:
        l = n//(k/2)
        m = n//k
        l -= m
        print(int(l**3+m**3))

def J():
    n = I()
    d = defaultdict(int)
    for i in range(n):
        a = I()
        if d[a]:
            d[a] -= 1
        else:
            d[a] += 1
    print(sum(d.values()))

def K():
    n,h = LI()
    v = LIR(n)
    s = 0
    i = 0
    v.sort()
    m = v[-1][0]
    v.sort(key = lambda x:-x[1])
    for a,b in v:
        if b > m:
            s += b
            i += 1
            if s >= h:break
    ans = i+(max(0,h-s)//m)
    if max(0,h-s)%m>0:
        ans += 1
    print(ans)
#Solve
if __name__ == "__main__":
    H()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 = [int(x) for x in input().split()]

def main():
    divisible = []
    indivisible = []
    for n in range(1, N + 1):
        if n % K == 0:
            divisible.append(n)
        else:
            indivisible.append(n)

    divisible_ans = len(divisible) ** 3

    passed = list(filter(lambda n: (n % K) * 2 == K, indivisible))
    indivisible_ans = len(passed) ** 3

    # print("({}, {})".format(divisible_ans, indivisible_ans))

    print(divisible_ans + indivisible_ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
N,K=map(int,input().split())
if K%2==0:
    print((N//K)**3+(((N-K//2)//K+1)**3))
else:
    print((N//K)**3)

Submission status: Accepted

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

if k%2!=0:
    #odd
    ans=(n//k)**3
    
else:
    #even
    for i in range(1,n+1):
        if i%k==k//2:#including 0
            x+=1
    ans=x**3+(n//k)**3    
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if k%2==0:
    a = n // k
    b = n // (k/2) - a
else:
    a = n //k
    b = 0

print( int(a*a*a + b*b*b) )

Submission status: Accepted

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

count = N // K
count2 = 0
if K % 2 == 0:
    K2 = K // 2
    count2 = (N // K2) - count
ans = count * count * count
ans += count2 * count2 * count2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=list(map(int,input().split(" ")))
i=0
if k%2==1:
    i=1
    num1=0
    while i<=n:
        if i%k==0:
            num1+=1
        else:
            pass
        i+=1
    print(num1**3)
else:
    i=1
    num2=0
    num3=0
    while i<=n:
        if i%k==0:
            num2+=1
        elif i%k==k/2:
            num3+=1
        else:
            pass
        i+=1
    print(num2**3+num3**3)

Submission status: Accepted

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


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
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 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 pf(s): return print(s, flush=True)

"""
単体のみで目的の数になる数字を数える
その数のみの組み合わせ + その数と他の数の組み合わせでできるものを求める
偶数の場合と奇数の場合で変わってくる
奇数の場合、同じ数同士での組み合わせは作れない
5,3の場合、3/3/3しかない
5,5の場合、5/5/5
10, 5の場合、5/5/5, 5/5/10, 5/10/10,など
奇数の場合、Kは作れない。
Kの倍数のみ作れる
3
"""

#  N, K = LI()
#  K_list = []

#  if K%2 == 0:
#      # 偶数
#      # すべてi%K == 0かすべてi%K == K/2であるかのどちらかである
#      result = (N/K)**3
#      result += (N/(K//2))**3
#      print(result)
#  else:
#      # 奇数
#      print((N//K)**3)

def iin(): return int(input())
def nl(): return list(map(int, input().split()))
def ary(r, c, v): return [[v for _ in range(c)] for _ in range(r)]

n, k = nl()

d = dict()
for i in range(1, n + 1):
    t = i % k
    d[t] = d.get(t, 0) + 1
#  print(d)
ans = 0
if k % 2 == 0:
    #  import pdb,gnureadline
    #  pdb.set_trace()
    ans += d.get(k // 2, 0) ** 3
ans += d.get(0, 0) ** 3
print(ans)

Submission status: Accepted

Solution code:
# 整数全体をある数で割った余りで分類
# 余りが同じ整数はすべて同じ(合同≡)とみなす
# 加法、減法、乗法を行っても合同を保つことから
# (1) a + b ≡ 0 mod K
# (2) b + c ≡ 0 mod K
# (3) c + a ≡ 0 mod K
# (1) - (2) + (3) 2a ≡ 0 mod K
# Kが偶数の場合、mod K / 2 もゼロと合同になる
# Kが8の場合、mod 4 もゼロとなるものも対象となる
# Kで割った余りはKより小さい
# Kで割った余りの数が等しくなるものがいくつあるか数え
# a mod Kで全探索する
N, K = map(int, input().split())

Kn = [0] * K


def main():
    # a b c は 1 から
    for i in range(1, N + 1):
        Kn[i % K] += 1

    ans = 0

    # 余りはゼロから
    # a mod K 全探索
    for a in range(K):

        # b と c は a から見て 等価
        b = (K - a) % K

        if 2 * b % K != 0:
            continue

        ans += Kn[a] * Kn[b] * Kn[b]

    print(ans)
    return


main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n, k = list(map(int, input().split()))
    ans = 0
    count1 = 0
    count2 = 0

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

    ans += count1 ** 3

    if k % 2 == 0:
        ans += count2 ** 3

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,K=rl()
ans = 0
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 = (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())
count = 0

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

Submission status: Accepted

Solution code:
def fact(n: int)->int:
    if n == 1:
        return 1
    return n * fact(n-1)


def triangular_relationship(N: int, K: int)->int:
    res = 0
    if K % 2 == 1:
        odd, even = 0, 0
        for k in range(K, N+1, K):
            if k % 2 == 0:
                even += 1
            else:
                odd += 1

        res = sum(d*d*d for d in [odd, even])

        res += odd*odd*even
        res += odd*even*odd
        res += even*odd*odd

        res += even*even*odd
        res += even*odd*even
        res += odd*even*even
    else:
        leftK, leftK2 = 0, 0
        for k in range(K//2, N+1, K//2):
            if k % K == 0:
                leftK += 1
            else:
                leftK2 += 1

        res = sum(d*d*d for d in [leftK, leftK2])

    return res


if __name__ == "__main__":
    N, K = map(int, input().split())
    ans = triangular_relationship(N, K)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sum = k_n*k_n*k_n
if K % 2 == 0:
    if K * (N // K) + K // 2 <= N:
        sum += (k_n + 1) ** 3
    else:
        sum *= 2

print(sum)

Submission status: Accepted

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

def comb(n,k):
    if n<k:
        return 0
    r = 1
    for i in range(k):
        r *= (n-i)
    for i in range(k):
        r //= (k+1)
    return r
def perm(n,k):
    if n<k:
        return 0
    r = 1
    for i in range(k):
        r *= (n-i)
    return r

single = n//k
if k%2 == 0:
    single =  n//(k//2)

double = perm(single,2)*3
if k%2 == 0:
    odd = perm((single+1)//2,2)*3
    even = perm(single//2,2)*3
    double = odd + even

triple = perm(single,3)
if k%2 == 0:
    odd = perm((single+1)//2,3)
    even = perm(single//2,3)
    triple = odd + even

print(single + double + triple)

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
    elif K % 2 == 0 and i % (K//2) == 0:
        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:
    print((n//k)**3+(2*n//k-n//k)**3)

Submission status: Accepted

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

if __name__ == '__main__':
    C()

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 K%2 == 0:
    for i in range(1,N+1):
        if i%K == K//2:
            ans2 += 1
print(ans1**3 + ans2**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+(N-(N//K)*K)//(K//2))**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/2
Solved on 2019/3/
@author: shinjisu
"""


# ABC 108 C Triangular Relationship
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probC():
    N, K = getIntList()
    dmp((N, K))
    n = N // K
    if K % 2 == 0:
        h = n + (N % K) // (K//2)
    else:
        h = 0
    dmp((n, h), 'n,h')
    cn = n**3
    ch = h**3
    dmp((cn, ch), 'n**3,h**3')
    return cn + ch


debug = False  # True False
print(probC())

Submission status: Accepted

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

if k%2 != 0:
    print((n//k)**3)
    exit()
else:
    k = k//2
    n_max = n//k
    n_even = n_max//2
    n_odd = n_max-n_even
    print(n_even**3 + n_odd**3)
    exit()

Submission status: Accepted

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

l = []

k = 0
g1 = 0
g2 = 0

if K % 2 == 1:
	for i in range(1,N+1):
		if i % K == 0:
			k += 1
		
else:
	for i in range(1,N+1):
		if i % K == 0:
			g1 += 1
		elif i % K == K / 2:
			g2 += 1

print(k**3 + g1**3 + g2**3)

Submission status: Accepted

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


def solve(N: int, K: int):
    a = N // K
    if K % 2 == 0:
        if N%K >= K//2:
            b = a + 1
        else:
            b = a
        print(a**3+b**3)
    else:
        print(a**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())
remain = n % k
def f(x):
    if x == 0:
        return n // k
    return n // k + int(x <= remain)
ret = 0
for a in range(k):
    if (-2 * a) % k == 0:
        ret += f(a) * f(k-a) * f(k-a)
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

c = n // k if k % 2 == 1 else n // (k // 2)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N, K = map(int, lines.pop(0).split(' '))

    x = y = 0

    for i in range(1, N+1):
        if i % K == 0:
            x += 1
        elif K % 2 == 0 and i % K == K//2:
            y += 1
    if K % 2 == 0:
        print(x**3 + y**3)
    else:
        print(x**3)


#
# main
#

# 1. use list instead of stdin
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc108/tasks/arc102_a

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

ans = 0
if K % 2 == 0:
    # 余りが 全部 0 か全部 K//2 である数字の組み合わせ
    c1 = len([i for i in range(K, N + 1, K)])
    ans += c1 * c1 * c1
    c2 = len([i for i in range(K // 2, N + 1, K)])
    ans += c2 * c2 * c2
else:
    # 余りが 全部 K//2 である数字の組み合わせ
    c1 = len([i for i in range(K, N + 1, K)])
    ans += c1 * c1 * c1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

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

def combi_num(n):
# n 個 -> a, b, c の組み合わせ数を返す
	if n == 0:
		return 0
	elif n == 1:
		return 1
	elif n == 2:
		return 8
	else:
		return n + 3*n*(n-1) + n*(n-1)*(n-2)


# 1: Kの倍数の個数
num_1 = N // K

# 2: Kの倍数-K/2 の個数	
num_2 = 0
if K % 2 == 0:
	if N%K >= K//2:
		num_2 = num_1 + 1
	else:
		num_2 = num_1

print(combi_num(num_1) + combi_num(num_2))

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)//K+1)**3)

Submission status: Accepted

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

def main():
    a = (N//K)**3
    if K%2!=0:
        print(a)
        return
    else:
        b = ( (N+(K//2)) // K ) **3
        print(a+b)
        return

main()

Submission status: Accepted

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