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

Solution (Python):

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

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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(ass)

Solution (Python):
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)

Solution (Python):
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)

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


ans = (N // K) ** 3

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

print(int(ans))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):

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

Solution (Python):
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
        
        n = (max - min) // K + 1
        cnt += n * n
    a += 1
print(cnt)

Solution (Python):
N ,K = map(int, input().split())
k = N//K

ans = k**3

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

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

Solution (Python):
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))

Solution (Python):
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

Solution (Python):


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



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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):



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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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


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)

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):
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

Solution (Python):
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()

ans = (N // K) ** 3

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

print(ans)

Solution (Python):

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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):



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)

Solution (Python):
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())

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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()

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

Solution (Python):

import sys

input=sys.stdin.readline

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

ans=0



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


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

print(ans)