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:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, k = f.read_int_list()

    c1 = n / k
    c2 = (n+k/2) / k if k % 2 == 0 else 0

    return c1**3 + c2**3


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:
import sys
N,K=map(int,input().split())
if K%2==1:
    s=N//K
    print(s**3)
    sys.exit()
k=K//2
t=(N//K)**3
u=((N+K//2)//K)**3
print(t+u)

Submission status: Accepted

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

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

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:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
if k%2==1:
 print(int(n/k)**3)
else:
 print(int(n/k)**3+(int(n/(k/2))-int(n/k))**3)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

def main():
	n, k = map(int,input().split())
	ans = 0
	b = int(n/k)
	ans += b**3
	if k % 2 == 0:
		c = k/2
		d = int((n+c)/k)
		ans += d**3
	print(ans)

main()

Submission status: Accepted

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

ans = 0
for a in range(1, n + 1):
        q = a % k
        if (2 * q % k != 0):
            continue
        ans += ((n + q) // k) ** 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


s=N//K
res += s**3
#print(res)
if K%2==0:
    N+=K//2
    s=N//K
    res+=s**3
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    print((cnt**3)+(cnt2**3))

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

    print(cnt**3)

Submission status: Accepted

Solution code:
N, K = map( int, input().split())
L = [0]*K
for n in range(1,N+1):
    L[n%K] += 1
ans = 0
for a in range(1,N+1):
    if (2*a)%K == 0:
        ans += L[(K-a)%K]**2
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k = [int(x) for x in input().split()]

ret = 0
for b in range(1,n+1):
    r = k - b%k
    # print(b,r)
    if r==k:
        # print("|",(n//k)**2)
        ret += (n//k)**2
    elif (2*r)%k==0:
        if r<=n%k:
            # print("*", (n//k+1)**2)
            ret += (n//k+1)**2
        else:
            # print("*", (n//k)**2)
            ret += (n//k)**2
print(ret)
# print("---")
# ret = 0
# for a in range(1,n+1):
#     for b in range(1,n+1):
#         for c in range(1,n+1):
#             if (a+b)%k==0 and (b+c)%k==0 and (a+c)%k==0:
#                 # print(a,b,c)
#                 ret += 1
# print(ret)

Submission status: Accepted

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

if K%2 != 0:
    print((N//K)**3)
else:
    r = N%K
    if r < K/2:
        print((N//K)**3*2)
    else:
        print((N//K+1)**3+(N//K)**3)

Submission status: Accepted

Solution code:
from math import floor, ceil

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

ans = 0
for a in range(1, N + 1):
    if 2 * a % K != 0:
        continue
    ans += (floor((N + a) / K) - ceil((a + 1) / K) + 1) ** 2
print(ans)

Submission status: Accepted

Solution code:
from math import ceil, floor

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

if K % 2:
    Ms = range(K, N + 1, K)
else:
    Ms = range(K // 2, N + 1, K // 2)

ans = 0
for a in Ms:
    nMin = ceil((1 + a) / K)
    nMax = floor((N + a) / K)
    ans += (nMax - nMin + 1) ** 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import math
 
n, k = map(int, input().split())
c = 0
 
if k%2==0:
    if math.floor(2*n/k)%2==0:
        d=math.floor(2*n/k)/2
        c=2*d*d*d
    else:
        d=(math.floor(2*n/k)+1)/2
        c=d*d*d+(d-1)*(d-1)*(d-1)
    print(int(c))
else:
    d=math.floor(n/k)
    c=d*d*d
    print(int(c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n, k = map(int, input().split())
rec = defaultdict(int)
num = 0
for i in range(1, n + 1):
    if (2 * i) % k == 0:
        num += 1
    rec[i % k] += 1

for i, v in rec.items():
    if (2 * i) % k == 0:
        if v >= 1:
            num += v * (v - 1) * 3
        if v >= 2:
            num += v * (v - 1) * (v - 2)

print(num)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, raw_input().split())
    s = 0
    aa = k / 2 if k % 2 == 0 else k
    for a in xrange(aa, n + 1, aa):
        b_min = (a / k + 1) * k - a
        if b_min < a:
            s += ((n - (a / k + 1) * k + a) / k + 1) * ((a - b_min) / k) * 2
        s += (n - ((a / k + 1) * k - a)) / k + 1
    print s


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K):
    ans = 0
    for a in range(1, N+1):
        if (a + a % K) % K != 0:
            continue
        n = math.floor(((N-(K-a) % K))/K)
        m = math.floor((N-(a % K))/K)
        if (K-a) % K != 0:
            n += 1
        if a % K != 0:
            m += 1
        ans += n * m

    return ans


def main():
    N, K = read_int_n()
    print(slv(N, K))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,K=map(int,input().split())
if K%2==1:
    s=N//K
    print(s**3)
    sys.exit()
k=K//2
s=N//k
num=0
if s%2==0:
    print((s**3)//4)
    sys.exit()
t=((s//2+1)**2)*(s//2+1)
u=((s//2)**2)*(s//2)
print(t+u)

Submission status: Accepted

Solution code:
import sys
n, k = map(int, sys.stdin.readline().split())
m, l = n // k, n % k
if k % 2 > 0:
  ans = m * m * m
else:
  x = m
  if l >= k // 2:
    x += 1
  ans = m * m * m + x * x * x
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())
ans = 0
for a in range(1, n + 1):
    if (a % k == 0):
        ans += (n // k) ** 2
    else:
        q = a % k
        if (2 * q % k != 0):
            continue
        ans += ((n + q) // k) ** 2

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
if K%2==1:
    print((N//K)**3)
else:
    T=K//2
    even=0
    odd=0
    for i in range(1,N+1):
        x=T*i
        if x>N:
            continue
        if i%2==0:
            even+=1
        else:
            odd+=1
    print(even**3+odd**3)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
def com(a,b):
    r=1
    for i in range(b):
        r*=(a-i)
        r//=i+1
    return r
if k%2==0:
    x=0
    y=0
    for i in range(1,n+1):
        if i%k==k//2:
            x+=1
        if i%k==0:
            y+=1
    ans=0
    if x>=1:
        ans+=com(x,1)
    if x>=2:
        ans+=6*com(x,2)
    if x>=3:
        ans+=6*com(x,3)
    if y>=1:
        ans+=com(y,1)
    if y>=2:
        ans+=6*com(y,2)
    if y>=3:
        ans+=6*com(y,3)
    print(ans)
else:
    x=0
    for i in range(1,n+1):
        if i%k==0:
            x+=1
    ans=0
    if x>=1:
        ans+=com(x,1)
    if x>=2:
        ans+=6*com(x,2)
    if x>=3:
        ans+=6*com(x,3)
    print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ass = 0
for i in range(1,n+1):
    if 2*i%k == 0:
        x = 2*i//k
        y = (n+i)//k
        w = y-x+1
        if w == 1:
            ass += 1
        elif w == 2:
            ass += 7
        else:
            ass += 1 + 6*w-6 + 6*(w-1)*(w-2)//2
        #print(i,ass)
print(ass)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
def com(a,b):
    r=1
    for c in range(b):
        r*=(a-c)
        r//=c+1
    return r
if k%2==0:
    x=0
    y=0
    for i in range(1,n+1):
        if i%k==k//2:
            x+=1
        if i%k==0:
            y+=1
    ans=0
    if x>=1:
        ans+=com(x,1)
    if x>=2:
        ans+=6*com(x,2)
    if x>=3:
        ans+=6*com(x,3)
    if y>=1:
        ans+=com(y,1)
    if y>=2:
        ans+=6*com(y,2)
    if y>=3:
        ans+=6*com(y,3)
    print(ans)
else:
    x=0
    for i in range(1,n+1):
        if i%k==0:
            x+=1
    ans=0
    if x>=1:
        ans+=com(x,1)
    if x>=2:
        ans+=6*com(x,2)
    if x>=3:
        ans+=6*com(x,3)
    print(ans)

Submission status: Accepted

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

if K % 2 != 0:
    print( (N // K) ** 3)
    exit()
elif K == 2:
    if N % 2 == 0:
        print(((N // 2) ** 3) * 2)
    else:
        print(((N // 2) ** 3) + ((N // 2)+ 1) ** 3)
else:
    num =  N // (K // 2)
    if num % 2 == 0:
        print(((num // 2) ** 3) * 2)
    else:
        print(((num // 2) ** 3) + ((num // 2)+ 1) ** 3)

Submission status: Accepted

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

# 全部Kの倍数のパターン
ans = (N // K) ** 3
# 偶数の時は、全部Kの倍数+(K/2)のパターンでもよい
if K % 2 == 0:
  ans += ((N - K/2) // K + 1) ** 3

print(int(ans))

Submission status: Accepted

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

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

print(Ans)

Submission status: Accepted

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

else:
    k2 = k//2
    if k>n:
        if k2>n:
            print(0)
        elif k2==n:
            print(1)
    elif k==n:
        print(2)

    else:
        a = n//k
        a2 = n//k2 - a
        ans += a
        ans += a2
        if a>1:
            ans += a*(a-1)*3
            if a>2:
                ans+=a*(a-1)*(a-2)
        if a2>1:
            ans += a2*(a2-1)*3
            if a>2:
                ans+=a2*(a2-1)*(a2-2)
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

if __name__ == "__main__":
    N, K = map(int, raw_input().split(" "))

    res = (N // K) ** 3

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

Submission status: Accepted

Solution code:
# encoding:utf-8
def main():
	n, k = list(map(int, input().split()))
	
	if k % 2 == 0:
		ans = (n // k) ** 3 + ((n + k / 2) // k) ** 3
	else:
		ans = (n // k) ** 3
	print(int(ans))

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys

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

a = 1
cnt = 0
while a <= N:
    if (2 * a) % K == 0:
        min = ((1 + a - 1) // K + 1) * K
        max = (N + a) // K * K
        #print(a, min-a, max-a)
        n = (max - min) // K + 1
        cnt += n * n
    a += 1
print(cnt)

Submission status: Accepted

Solution code:
N ,K = map(int, input().split())
k = N//K
#あまりRとして(0,0,0)mod(K)の時
ans = k**3
#R/2
if K%2 == 0:
    k2 = k
    if (N%K)>=(K//2):
        k2 += 1
    ans += k2**3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if K%2 == 0:
    L = ((N//(K//2)-1)//2)+1
    print(pow(N//K,3)+pow(L,3))
else:
    print(pow(N//K,3))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# S = input()
# N = int(input())
N, K = map(int, input().split())
# X = list(map(int, input().split()))
# LR = [list(map(int, input().split())) for _ in range(N)]

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = int(n / k) ** 3

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,k = li()

# すべてmod k == 0
mod0 = 0
modk2 = 0
for i in range(1,n+1):
    if i%k == 0:
        mod0 += 1
        
    if i%k == (k/2):
        modk2 += 1
        
ans = (modk2**3 + mod0**3)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left
def inpl(): return list(map(int, input().split()))
N, K = inpl()
if K%2==0:
    X = N//K
    Y = N//(K//2) - X
    print(Y**3 + X**3)
else:
    X = N//K
    print(X**3)

Submission status: Accepted

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


nbc=[0]

nbk=[0]*k

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

res=0
for i in range(k):
    if (i+i)%k==0:
        res+=nbk[i]**3

print res

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

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

N, K = reads()
# a == b == c == 0 (mod K)
ans = (N // K) ** 3

if K % 2 == 0:
  # a == b == c == K/2 mod K
  ans += ((N + (K//2)) // K) ** 3

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

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

if K % 2 == 1:
    NK = N // K
    NK2 = 0
else:
    NK = N // K
    NK2 = N // (K//2) - NK
debug(NK, NK2)
print(NK**3 + NK2**3)

Submission status: Accepted

Solution code:
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

n, k = mi()
c1 = c2 = 0
for i in range(1, n + 1):
    c1 += i % k == 0
    c2 += k % 2 == 0 and i % k == k // 2
ans = c1 ** 3 + c2 ** 3
print(ans)

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


N, K = map(int, input().split())
if K % 2 == 1:
    hoge = N // K
    print(hoge * hoge * hoge)
else:
    hoge = N // K
    half = hoge
    if K * hoge + K // 2 <= N:
        half += 1

    ans = hoge * hoge * hoge
    ans += half * half * half
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

else:
    a=(N//K)**3
    b=((N+K//2)//K)**3

    print(a+b)

Submission status: Accepted

Solution code:
def getIntList():
    return list(map(int, input().split()))    
 
N, K = getIntList()
 
res = 0
c1 =0
c2 =0
if K %2 ==0:
    t = K//2
else:
    t= -1
 
if True:
    for i in range(1,N+1):
        if i%K == t:
            c1+=1
        if i%K ==0:
            c2+=1
res =  c1 **3 + c2** 3
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,K = inpl()

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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


if k%2!=0:
    print((n//k)**3)
else:
    k=k//2
    a = n//k
    gu = n//(2*k)
    ki = a-gu
    print((ki)**3+(gu)**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**13
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)


def main():
    n,k = LI()
    t = n // k
    r = t ** 3
    if k % 2 == 0:
        k //= 2
        tt = n // k
        if tt % 2 == 1:
            r += (tt//2+1) ** 3
        else:
            r += (tt//2) ** 3

    return r


print(main())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# C
N, K = map(int, input().split())
if K % 2 == 1:
    res = (N // K)**3
else:
    a = N // K
    b = N // (K // 2)
    res = a ** 3 + (b-a)**3
print(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) // k + 1) ** 3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = (N/K)**3

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

print x

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
    b = (n-(k//2))//k + 1
    print(a**3 + b**3)

Submission status: Accepted

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

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

a = n // k
b = (n + (k//2)) // k

print(a**3 + b**3)

Submission status: Accepted

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

n, k = [int(x) for x in input().split()]

print(func(n, k))

Submission status: Accepted

Solution code:
USE_STDIO = False

if not USE_STDIO:
    try: import mypc
    except: pass

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

    x = n // k
    ans += x ** 3

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

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

ans = (N / K) ** 3

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

print ans

Submission status: Accepted

Solution code:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

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

ans=0

# a,b,c are the same, mod k
# do a,b,c = 0 mod k
ans+=(n//k)**3

# do a,b,c = k/2 mod k
if k%2==0:
    ans+=((n+k//2)//k)**3

print(ans)

Submission status: Runtime Error

Solution code:
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
amari=[0]*k
for i in range(n):
    i+=1
    amari[i%k]+=1
# print(amari)

ans=0
for i in range(n):
    i+=1
    am=i%k
    nokori=(k-am)%import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
amari=[0]*k
for i in range(n):
    i+=1
    amari[i%k]+=1
# print(amari)

ans=0
for i in range(n):
    i+=1
    am=i%k
    nokori=(k-am)%k
    # print(am,nokori)
    if nokori*2%k==0:
        ans+=amari[nokori]**2
print(ans)
    # print(am,nokori)
    if nokori*2%k==0:
        ans+=amari[nokori]**2
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

cnt = [0] * (n + 1)

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

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

Submission status: Runtime Error

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

cnt = [0] * (n)

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

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

Submission status: Runtime Error

Solution code:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    N,K = LMIIS()
    ans = 0

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

    #(N//K) ありうるKの倍数の数(0以外)

    #a,b,c,全部がKの倍数 のパターン
    ans += (N//K)**3
    #a,b,c,全部がKの倍数+K//2　のパターン
    ans += ((N-K//2)//K+1)**3
    print(ans)


    


    





    
main()

Submission status: Runtime Error

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

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

else:
    tmp = N // K
    ans = tmp ** 3

    tmp = N // (K // 2) - tmp
    ans += tmp ** 3

    print (ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
u1, u2=divmod(N,K)
ans=u1**3

A=[u1]*K
for i in range(u2):
    A[i+1]+=1
if K%2==0:
    ans+=A[K//2+1]**3
print(ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
u1, u2=divmod(N,K)
ans=u1*3

A=[u1]*K
for i in range(u2):
    A[i+1]+=1
if K%2==0:
    ans+=A[K//2+1]*3
print(ans)