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:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

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

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

N, K = list(map(int, sys.stdin.readline().split()))
if K % 2 == 1:
    # K の倍数のパターンのみ
    m = N // K
    print(m ** 3)
else:
    m = N // K
    a1 = m ** 3
    m = (N + K // 2) // K
    a2 = m ** 3
    print(a1 + a2)

Submission status: Accepted

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

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

if k % 2:
    print((n//k)**3)
else:
    x = n//k
    y = n//(k//2)
    y -= x
    print(x**3 + y**3)

Submission status: Accepted

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

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

c = int(N / K)
ans += c ** 3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
d = []
for i in range(1, a + 1):
    if i % b == 0:
        c.append(i)
    elif i % b == b / 2:
        d.append(i)
e = 0
print(len(c) * len(c) * len(c) + len(d) * len(d) * len(d))

Submission status: Accepted

Solution code:
# editorial,解説ブログを参考にした(偶数の場合の考え方)
N, K = map(int, input().split())
ans = 0
if K % 2 == 1:
    ans = (N // K) ** 3
else:
    ans += (N // K) ** 3
    ans += ((N+(K/2))//K) ** 3
print(int(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(int(ans))

Submission status: Accepted

Solution code:
def solve(N, K):
    n = N // K
    #print(n)
    answer = n ** 3
    if K % 2 == 0:
        m = K//2
        n = (N + m) // K
        #print(n)
        answer += n ** 3
    return answer
        
N, K = [int(x) for x in input().split()]
print(solve(N, K))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if k%2==1:
    num=0
    for i in range(1,n+1):
        if i%k==0:
            num+=1
    print(num**3)
else:
    num1=0
    num2=0
    for i in range(1,n+1):
        if i%k==0:
            num1+=1
        elif i%k==int(k/2):
            num2+=1
    print(num1**3+num2**3)

Submission status: Accepted

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

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

    print(num**3)

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

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

    print(num1**3+num2**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
count = 0
count2 = 0
ans = 0
f = False
if K % 2 == 0:
    f = True
for n in range(1,N+1):
    if n % K == 0:
        count += 1
    if f and n % K == K//2:
        count2 += 1 
if f:
    ans = count2 ** 3 + count ** 3
else:
    ans = count ** 3
print(ans)

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans1 = 0
ans2 = 0
for a in range(1, n + 1):
    if a % k == 0:
        ans1 += 1
    if k % 2 == 0 and a % k == k / 2:
        ans2 += 1
ans = ans1 ** 3
if k % 2 == 0 and ans2 > 0:
    ans += ans2**3
print(ans)

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
 
result = 0
 
if (K%2) == 1:
    kouho = N//K
    result+=kouho*kouho*kouho
 
else:
    kouho1 = N//K
    kouho2 = N//(K/2) - kouho1
    result+=kouho1*kouho1*kouho1
    result+=kouho2*kouho2*kouho2
 
print(int(result))

Submission status: Accepted

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

if K&1:
  # 全部Kの倍数
  answer = (N//K) ** 3
else:
  KK = K//2
  # 全部KKの奇数倍 or 全部偶数倍
  even = N // K
  odd = (N//KK) - even
  answer = even ** 3 + odd ** 3

print(answer)

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())
a=n//k
if k%2==0:
  b=0
  for i in range(1,n+1):
    if i%k==int(k/2):
      b+=1
  print(a**3+b**3)
else:
  print(a**3)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

# # PROCESS
answer = 0
memo = 0
only_even = 0
for i in range(1, n+1):
  if k % 2 == 0:
    if i % k == 0:
      memo += 1
    if i % k == k/2:
       only_even += 1
  else:
    if i % k == 0:
      memo += 1

answer = memo * memo * memo
answer += only_even * only_even * only_even
# # OUTPUT
print(answer)

Submission status: Accepted

Solution code:
def resolve():
    (N, K) = list(map(int, input().split(" ")))
    srps = [0] * (K+1)
    # srps[n]: Kで割った余りがnである数が1~Nの間にいくつ存在するか
    for i in range(1, N+1):
        srps[i%K] += 1
    cnt = 0

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

        

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

div = N//K

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

def solve1():
    no_rem = 0
    rem_half = 0

    for i in range(1,n+1):
        no_rem += 1 if i % k == 0 else 0

        rem_half += 1 if k%2 == 0 and i%k == k//2 else 0

    print(no_rem ** 3 + rem_half**3)
    

def solve2():
    no_rem = n//k

    rem_half = 0 if k%2==1 else (n + k//2)//k
    print(no_rem**3 + rem_half**3)

solve2()

Submission status: Accepted

Solution code:

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

no_rem = 0
rem_half = 0

for i in range(1,n+1):
    no_rem += 1 if i % k == 0 else 0

    rem_half += 1 if k%2 == 0 and i%k == k//2 else 0

print(no_rem ** 3 + rem_half**3)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

# kが奇数ならa,b,cはkの倍数
# kが偶数ならa,b,cはk/2の倍数

if k % 2 == 1:
  print((n//k)**3)
else:
  k_1 = (n//k)**3 #a,b,cが全てkの倍数
  k_2 = ((2*n)//k - n//k)**3 #a,b,cがk/2の奇数倍
  print(k_1+k_2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, k = f()
    if k&1:
        print((n//k)**3)
    else:
        add = 1 if n%k>= (k//2) else 0
        print((n//k + add)**3  + (n//k)**3)



solve()

Submission status: Accepted

Solution code:
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
ans = 0
a = 0
b = 0
if K % 2 == 0:
    for i in range(1,N+1):
        if i % K == 0:
            a += 1
        if i % K == (K/2):
            b += 1
    print(a**3 + b**3)
else:
    for i in range(1,N+1):
        if i % K == 0:
            a += 1
    print(a**3)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

else:
    x = 0
    y = 0
    
    # Kで割った時、余りが0になる数字の個数
    for i in range(K, N+1):
        if not i % K:
            x += 1

    # Kで割った時、余りがK/2になる数字の個数
    for i in range(1, N+1):
        if 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==0:
  a=int(n/k)
  b=int((n+k/2)/k)
  print(a**3+b**3)
else:
  a=int(n/k)
  print(a**3)

Submission status: Accepted

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


def solve(N: int, K: int):
    k0 = 0
    kh = 0
    if K % 2 == 1:
        k0 = N // K
    else:
        k0 = N // K
        kh = (N+(K//2)) // K

    print(k0**3 + kh ** 3)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if k % 2 == 1:
    d = n // k
    print(d ** 3)
else:
    l = k // 2
    d1 = (n + l) // k
    d2 = n // k
    print(d1 ** 3 + d2 ** 3)

Submission status: Accepted

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

mod_K_zero = len([i for i in range(1, N+1) if i % K == 0])
mod_K_half = len([i for i in range(1, N+1) if i % K == K/2])

print(pow(mod_K_zero, 3) + pow(mod_K_half, 3))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Triangular Relationship
https://atcoder.jp/contests/abc108/tasks/arc102_a

"""
import sys


def solve(N, K):
    if K == 1:
        return N**3
    if K % 2:
        return (N // K)**3
    res1 = sum([i%K == 0 for i in range(1, N+1)])
    res2 = sum([i%K == K//2 for i in range(1, N+1)])
    return res1**3 + res2**3


def main(args):
    N, K = map(int, input().split())
    ans = solve(N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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 = list(map(int, input().split()))
count = N // K
if K % 2 == 1:
  print(count**3)
else:
  print(count**3 + (count+(N%K)//(K//2)) ** 3)

Submission status: Accepted

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

ans = 0
a = N // K

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

print(ans)

Submission status: Accepted

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

if k % 2 == 1:
    for i in range(1, n+1):
        if i % k == 0:
            cnt += 1
    ans = cnt ** 3
elif k % 2 == 0:
    cnt1 = 0
    cnt2 = 0
    for i in range(1, n+1):
        if i % k == 0:
            cnt1 += 1
        elif i % k == k/2:
            cnt2 += 1
    ans = cnt1 ** 3 + cnt2 ** 3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for a in range(1, N+1):
    b = K - a % K
    if (a % K) == (b % K):
        count += ((N - b) // K + 1) ** 2

print(count)

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


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

    ans = (n // k) ** 3

    if k & 1:
        print(ans)
        return

    ans += ((n + k // 2) // k) ** 3
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if k % 2 == 0:
    a = int(n/k)
    b = int((n+k/2)/k)
    print(a**3 + b**3)

else:
    a = int(n/k)
    print(a**3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
if k%2 == 0:
    #k mod halfの個数は
    mod1 = (n+(k//2))//k
    #k mod0の個数は
    mod2 = n//k
    
    ans += mod1**3 + mod2**3
    
else:
    #kmod0の個数は
    modk = n//k
    
    ans += modk**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:
# -*- coding: utf-8 -*-

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

#Kの偶奇で場合分け
#Kが偶数なら(x,y,z) x, y, z = K/2, 0 (mod K) でKが奇数なら(x,y,z) x, y, z = 0 (mod K)

output = 0

output += int(N / K)**3

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

print (output)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, K: int):
    ns0 = len(range(K, N+1, K))
    ret = ns0 ** 3

    if K % 2 == 0:
        ns1 = len(range(K//2, N+1, K))
        ret += ns1 ** 3

    return ret


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import itertools

N, K = map(int, input().split())
div = []
rest = []
for n in range(1, N+1):
    if K % 2 == 1:
        if n % K  == 0:
            div.append(n)
    else:
        if n % K  == 0:
            div.append(n)
        elif n % K == K/2:
            rest.append(n)

D = len(div)**3
R = len(rest)**3

print(D+R)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = list(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
#ｋで割り切れるn以下の数のリスト
odd = [i for i in range(k, n+1, k)] #kから始まり、nまで、ｋ刻み
ans += len(odd) ** 3 #abcの選び方のため3乗

if k % 2 == 0:
  #k/2から始まり、nまでで、kで割ると余りがk/2になる
  even = [i for i in range(k//2, n+1, k)]
  ans += len(even) ** 3
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if k % 2 != 0:
    print((n//k)**3)
else:
    print((n//k)**3+((n+int(k/2))//k)**3)

Submission status: Accepted

Solution code:


def main():
    num, k_num = map(int, input().split())

    count_all, count_half = 0, 0
    for i in range(1, num + 1):
        if i % k_num == 0:
            count_all += 1
        elif i % k_num == k_num // 2 and k_num % 2 == 0:
            count_half += 1

    print(int(count_all**3 + count_half**3))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
 
#奇数の時
if K%2:
    a = N//K
    print(a**3)
#偶数の時
else:
    #Nまででa,b,cそれぞれがKで割り切れる数(割り切れる数同士の和も割り切れる)
    a = N//K
    #あまりがk/2(和がkの倍数になる場合)
    b = (N+K//2)//K
    print(a**3 + b**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

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

	ans = 0
	ans2 = 0
	for i in range(1, N+1):
		if i % K == 0:
			#print(i)
			ans += 1
		elif K % 2 == 0 and i % K == K/2:
			#print(i)
			ans2 += 1
	
	print(ans*ans*ans + ans2*ans2*ans2)

	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

        ans += base ** 3

        print(ans)

Submission status: Accepted

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


def solve(N: int, K: int):
    ret = (N // K) ** 3
    if K % 2 == 0:
        tmp = K // 2
        count = 1 + (N - tmp) // K
        ret += count ** 3
    print(ret)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, K: int):
    candidate = 0
    if K % 2 == 0:
        candidate = math.floor(N / (K//2))
        evenCandidate = math.floor(candidate / 2)
        oddCandidate = candidate - evenCandidate
        print(evenCandidate ** 3 + oddCandidate**3)
    else:
        candidate = math.floor(N/K)
        print(candidate**3)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 = (n//k)**3
if k%2 == 0:
	ans += ((n+(k//2))//k)**3

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

	print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

remainder = []
for i in range (1,N+1):
    remainder.append(i%K)
    
if K%2==0:
    print(remainder.count(K//2)**3+remainder.count(0)**3)
else:
    print(remainder.count(0)**3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def comb(x):
    return x ** 3


if K % 2 == 0:
    n = N // K
    m = N // (K // 2) - n
    print(comb(n)+comb(m))
else:
    print(comb(N//K))

Submission status: Accepted

Solution code:
def solve(n, k):
    m = n // k
    res = m**3
    if k % 2 == 0:
        m2 = n // (k // 2) - m
        res += m2**3
    return res 

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

print(a+(N//K)**3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# kが奇数のとき、n//k**3となる
# kが偶数の時、a≡b≡c mod(k//2)となり、上述プラス.
n,k = map(int,input().split())
ans=0
if k%2==1:
    ans+=(n//k)**3
    print(ans)
else:
    ans+=(((n-k//2)//k + 1)**3)
    ans+=(n//k)**3
    print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    print(solve(n, k))

def solve(n, k):
    r = (n // k) ** 3

    if k % 2 == 0:
        x = n // k
        if n % k >= k // 2:
            x += 1
        r += x ** 3

    return r

main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
temp = n // k
ans += temp ** 3

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

Submission status: Accepted

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