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: Time Limit Exceeded

Solution code:
import fractions
N,K=map(int,input().split())
def f(x):
  import math
  if x==1:
    if 2%K==0:
      return 1
    else:
      return 0
  elif x==2:
    m=0
    if 4%K==0:
      m+=1
    if K==1:
      m+=6
    return m+f(1)
  else:
    n=0
    if (2*x)%K==0:
      n+=1
    for i in range(1,x):
      if (i+x)%K==0:
        if (2*i)%K==0:
          n+=3
        if (2*x)%K==0:
          n+=3
    for j in range(1,x-1):
      for k in range(j+1,x):
        m=fractions.gcd(j+x,k+x)
        if m%K==0:
          if (fractions.gcd(m,j+k))%K==0:
            n+=6
    return n+f(x-1)
print(f(N))

Submission status: Time Limit Exceeded

Solution code:
n, k= map(int, input().split())
List=[1 for i in range(1, n+1)
      for j in range(1, n+1)
      for l in range(1, n+1) if (i+j)%k==0 and (j+l)%k==0 and (i+l)%k==0]

print(len(List))

Submission status: Time Limit Exceeded

Solution code:
n, k= map(int, input().split())
count=0
for i in range(1, n+1):
    for j in range(1, n+1):
        for l in range(1, n+1):
            if (i+j)%k==0 and (j+l)%k==0 and (i+l)%k==0:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N, K = map(int, input().split())
combs = deque()
ans = 0
a = 1
while a <= N:
  b = K - a
  while b <= N:
    if b >=  a:
      c = K - a
      while c <= N:
        if c >= b and (b+c)%K == 0 and (c+a)%K == 0:
          combs.append([a, b, c])
        c += K
    b += K
  a += 1
for (a, b, c) in combs:
  if a==b and b==c:
    ans += 1
  elif a == b or b == c or c == a:
    ans += 3
  else:
    ans += 6
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
ans = 0
a = 1
while a <= N:
  b = K - a
  while b <= N:
    if b >=  1:
      c = K - a
      while c <= N:
        if c >= 1 and (b+c)%K == 0 and (c+a)%K == 0:
          ans += 1
        c += K
    b += K
  a += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

count = 0
for a in s:
    for b in s:
        for c in s:
            if (a + b) % k == 0 and (b + c) % k == 0 and (c + a) % k == 0:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

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

m = set()
p = 0
for a in range(1, N + 1): # 10 3
    for b in range(K - (a % K), N + 1, K):
        for c in range(K - (b % K), N + 1, K):
            p += 1
            if (c + a) % K == 0:
                m.add((a, b, c))

print(len(m))
# very slow

Submission status: Time Limit Exceeded

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

i = 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 ((c+a)%K ==0):
				i +=1
print(i)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
l=[i for i in range(1,n+1) if (2*i)%k==0]
cnt=0
for x in range(len(l)):
    for y in range(len(l)):
        for z in range(len(l)):
            if (l[x]+l[y])%k==0 and (l[y]+l[z])%k==0 and (l[z]+l[x])%k==0:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(d,N+1,d):
    for j in range(d,N+1,d):
        for k in range(d,N+1,d):
            if (i+j)%K==0 and (j+k)%K==0 and (k+i)%K==0:
                c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
c=0
if K%2==0:
    d=K//2
else:
    d=K

for i in range(d,N+1,d):
    for j in range(d,N+1,d):
        for k in range(d,N+1,d):
            if (i+j)%K==0 and (j+k)%K==0 and (k+i)%K==0:
                c+=1
print(c)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(K, N+1, K):
    for j in range(K, N+1, K):
        for k in range(K, N+1, K):
            ans += 1
if K % 2 == 0:
    for i in range(K//2, N+1, K):
        for j in range(K//2, N+1, K):
            for k in range(K//2, N+1, K):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(K, N+1, K):
    for j in range(K, N+1, K):
        for k in range(K, N+1, K):
            ans += 1
if K % 2 == 0:
    for i in range(1, N+1):
        if i % K != K // 2:
            continue
        for j in range(1, N+1):
            if j % K != K // 2:
                continue
            for k in range(1, N+1):
                if k % K != K // 2:
                    continue
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ret = 0

for a in range(1, N + 1):
    if 2 * a % K != 0:
        continue

    cnt = 0
    t = 1
    while t * K - a <= N:
        if t * K - a >= 1:
            cnt += 1
        t += 1

    ret += cnt ** 2

print(ret)

Submission status: Time Limit Exceeded

Solution code:
n, k = [int(i) for i in input().split()]
cnt = 0
for i in range(1,2*n//k+1):
    if i*k%2 ==1 and k%2 == 1:
        for j in range((i-1)//2):
            a = i*k//2 - (k+2*k*j-1)//2
            if i * k - a <= n:
                cnt += ((a+n)//k - a//k)*2
    elif i*k%2 == 0:
        if k%2 == 0:
            for j in range(i-1):
                a = i * k // 2 - (k + k * j) // 2
                if i*k-a <= n:
                    cnt += ((a + n) // k - a // k) * 2
        else:
            for j in range(1,i // 2):
                a = i * k // 2 - k * j
                if i * k - a <= n:
                    cnt += ((a + n) // k - a // k) * 2
        cnt += ((i*k//2 + n) // k - (i*k//2) // k)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

cnt = 0
for i in range(1,2*n//k+1):
    for j in range(max(1, k*i-n), min(k*i//2+1, n+1)):
        a = j
        b = k*i-a
        if a == b:
            d = 1
        else:
            d = 2
        if (b-a) % k == 0:
            cnt += ((a+n)//k - a//k)*d
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

cnt = 0
for i in range(1,2*n//k+1):
    for j in range(1, min(k*i, n+1)):
        a = j
        b = k*i-a
        if b <= n and (b-a)%k == 0:
            cnt += (a+n)//k- a//k
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

cnt = 0
for i in range(1,2*n//k+1):
    for j in range(1, min(k*i, n+1)):
        a = j
        b = k*i-a
        if b <= n:
            for m in range(a//k+1,(a+n)//k+1):
                c = m*k - a
                if (c + b)%k == 0:
                    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

for num in range(1, n+1):
    if (2 * num) % k == 0:
        num_list.append(num)
# print(num_list)
count = 0
for a in num_list:
    for b in num_list:
        if (a + b) % k == 0:
            for c in num_list:
                if (b + c) % k == 0 and (a + c) % k == 0:
                    # print(str(a) + str(b) + str(c))
                    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

def comb(n,r):
  return factorial(n) / (factorial(r) * factorial(n-r)) if n >= r else 0

if K%2 == 1:
  cand = N // K
  print(int(cand + comb(cand,2) * 6 + comb(cand,3) * 6))
else:
  cand_mod0 = N // K
  ans_mod0 = cand_mod0\
           + cand_mod0 * (cand_mod0-1) * 3\
           + cand_mod0 * (cand_mod0-1) * (cand_mod0-2)
  cand_modhalf = N // K if N % K < K / 2 else (N // K) + 1
  ans_modhalf = cand_modhalf\
           + cand_modhalf * (cand_modhalf-1) * 3\
           + cand_modhalf * (cand_modhalf-1) * (cand_modhalf-2)
  print(int(ans_mod0 + ans_modhalf))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

def comb(n,r):
  return factorial(n) / (factorial(r) * factorial(n-r)) if n >= r else 0

if K%2 == 1:
  cand = N // K
  print(int(cand + comb(cand,2) * 6 + comb(cand,3) * 6))
else:
  cand_mod0 = N // K
  ans_mod0 = cand_mod0 + comb(cand_mod0, 2) * 6 + comb(cand_mod0, 3) * 6
  cand_modhalf = N // K if N % K < K / 2 else (N // K) + 1
  ans_modhalf = cand_modhalf + comb(cand_modhalf, 2) * 6 + comb(cand_modhalf, 3) * 6
  print(int(ans_mod0 + ans_modhalf))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
k = 2*N // K
ans = 0
for a in range(1, N+1):
    b = 0
    if 2*a %K != 0:
        continue
    kmin = a//K +1
    for i in range(kmin, k+1):
        if i*K - a > N:
            break
        b += 1
    ans += b*b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
k = 2*N // K
ans = 0
for a in range(1, N+1):
    b = 0
    c = 0
    if 2*a %K != 0:
        continue
    kmin = a//K +1
    for i in range(kmin, k+1):
        if i*K - a > N:
            break
        b += 1
    for j in range(kmin, k+1):
        if j*K -a > N:
            break
        c += 1
    ans += b*c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
ans = 0
for i in range(1,N+1):
    if 2*i % K != 0:
        continue
    for j in range(1, N+1):
        if 2*j % K != 0:
            continue
        if (i+j)% K != 0:
            continue
        for k in range(1, N+1):
            if 2*k % K != 0:
                continue
            if (i+k) % K != 0:
                continue
            if (j+k) % K != 0:
                continue
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k=map(int,input().split())
a=list(range(n))
a=list(map(lambda x: x+1, a))
ans=0
for balls in itertools.product(a,repeat=3):
  one=balls[0]+balls[1]
  one=one%k
  two=balls[1]+balls[2]
  two=two%k
  twr=balls[0]+balls[2]
  twr=twr%k
  if(one==0 and two==0 and twr==0):
    ans+=1
print(str(ans))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations_with_replacement
from itertools import combinations
from itertools import permutations


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


nums = [x for x in range(1, N+1)]

res = {}
for cwr in combinations_with_replacement(nums, 3):
	rems = [sum(c) % K for c in combinations(cwr, r=2)]
	if 0 == sum(rems):
		for p in permutations(cwr):
			res[p] = 1

print len(res.keys())

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations_with_replacement
from itertools import combinations
from itertools import permutations


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


nums = [x for x in range(1, N+1)]

meets = []
for cwr in combinations_with_replacement(nums, 3):
	rems = [sum(c) % K for c in combinations(cwr, r=2)]
	if 0 == sum(rems):
		meets.append(cwr)

res = {}
for m in meets:
	for p in permutations(m):
		res[p] = 1

print len(res.keys())

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
count=0
for a in range(1,n+1):
    for m in range(1,(2*n)//k+1):
        b = k * m - a
        if b <= 0 or b > n:
            continue
        for l in range(1,(2*n)//k+1):
            c = k * l - b
            if c <= 0 or c > n:
                continue
            if (b + c) % k == 0 and (b + a) % k == 0 and (a + c) % k == 0:
                count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
b=list(map(int,input().split(" ")))
c=2*b[0]/b[1]
t=0
for i in range(1,int(c)+1):
    for j in range(1,int(c)+1):
        for k in range(1,int(c)+1):
            if (i+j-k)/2*b[1]>=1 and (i+j-k)/2*b[1]<=b[0] and math.modf((i+j-k)/2*b[1])[0]==0:
                if (k+j-i)/2*b[1]>=1 and (k+j-i)/2*b[1]<=b[0] and math.modf((k+j-i)/2*b[1])[0]==0:
                    if (i+k-j)/2*b[1]>=1 and (i+k-j)/2*b[1]<=b[0] and math.modf((i+k-j)/2*b[1])[0]==0:
                        t+=1
                        
print (t)

Submission status: Time Limit Exceeded

Solution code:
import math
from itertools import product
b=list(map(int,input().split(" ")))
c=2*b[0]/b[1]
a=[i for i in range(1,int(c)+1)]
a=list(product(a,repeat=3))
t=0
for i in a:
    if (i[0]+i[1]-i[2])*b[1]/2.0>=1 and (i[0]+i[1]-i[2])*b[1]/2.0<=b[0] and math.modf((i[0]+i[1]-i[2])*b[1]/2.0)[0]==0:
        if (i[0]+i[2]-i[1])*b[1]/2.0>=1 and (i[0]+i[2]-i[1])*b[1]/2.0<=b[0] and math.modf((i[0]+i[2]-i[1])*b[1]/2.0)[0]==0:
            if (i[2]+i[1]-i[0])*b[1]/2.0>=1 and (i[2]+i[1]-i[0])*b[1]/2.0<=b[0] and math.modf((i[2]+i[1]-i[0])*b[1]/2.0)[0]==0:
                t+=1
print (t)

Submission status: Time Limit Exceeded

Solution code:
import math
from itertools import product
b=list(map(int,raw_input().split(" ")))
c=2*b[0]/b[1]
a=[i for i in range(1,c+1)]
a=list(product(a,repeat=3))
t=0
for i in a:
    if (i[0]+i[1]-i[2])*b[1]/2.0>=1 and (i[0]+i[1]-i[2])*b[1]/2.0<=b[0] and math.modf((i[0]+i[1]-i[2])*b[1]/2.0)[0]==0:
        if (i[0]+i[2]-i[1])*b[1]/2.0>=1 and (i[0]+i[2]-i[1])*b[1]/2.0<=b[0] and math.modf((i[0]+i[2]-i[1])*b[1]/2.0)[0]==0:
            if (i[2]+i[1]-i[0])*b[1]/2.0>=1 and (i[2]+i[1]-i[0])*b[1]/2.0<=b[0] and math.modf((i[2]+i[1]-i[0])*b[1]/2.0)[0]==0:
                t+=1
print t

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
c=0
s = k if k%2==1 else k//2
for i in range(s,n+1,s):
    for j in range(s,n+1,s):
        for l in range(s,n+1,s):
            if (i+j)%k==0 and (i+l)%k==0 and (j+l)%k==0:
                c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
count = 0
for a in range(1,N+1):
	for b_alt in range(K,N*2+1,K):
		if b_alt - a <= 0 or b_alt - a > N:
			continue
		else:
			b = b_alt - a
		for c_alt in range(K,N*2+1,K):
			if c_alt - a <= 0 or c_alt - a > N:
				continue
			elif (b + c_alt - a)%K != 0:
				continue
			else:
				count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt = 0

if k % 2 == 0:
  k_2 = k // 2
else:
  k_2 = k

for a in range(k_2, n+1, k_2):
  for b in itertools.product(range(k-(a%k), n+1, k), repeat=2):
    cnt += len(b) // 2
        
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

if k % 2 == 0:
  k_2 = k // 2
else:
  k_2 = k

for a in range(k_2, n+1, k_2):
  for b in range(k-(a%k), n+1, k):
    for c in range(k-(a%k), n+1, k):
      cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

if k % 2 == 0:
  k_2 = k // 2
else:
  k_2 = k

for a in range(k_2, n+1, k_2):
  for b in range(k-(a%k), n+1, k):
    for c in range(k-(a%k), n+1, k):
      if (b + c) % k == 0:
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a=input()
a=a.split(" ")
i=0
n=int(a[0])
g=int(a[1])
for x in range(1,n+1):
    for y in range(1,n+1):
        for z in range(1,n+1):
            if (x+y)%g==0 and (y+z)%g==0 and (z+x)%g==0:
                i=i+1
print(i)

Submission status: Time Limit Exceeded

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

result = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        tmp1 = a + b
        bool1 = tmp1 % K == 0
        if not bool1:
            continue

        for c in range(1, N+1):
            tmp2 = b + c
            bool2 = tmp2 % K == 0
            if not bool2:
                continue

            tmp3 = c + a

            if bool1 and bool2 and (tmp3 % K ==0):
                result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
input_text = input()
arg =  input_text.split(' ')
N = int(arg[0])
K = int(arg[1])

sum = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        ans1 = (a + b) % K == 0
        for c in range(1, N+1):
            ans2 = (b + c) % K == 0
            ans3 = (c + a) % K == 0

            if ans1 and ans2 and ans3:
                sum += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
a = input().split(" ")
b = int(a[0])
count = 0
for x in range(b):
  for y in range(b):
    for z in range(b):
      c = (x+1) + (y+1)
      d = (x+1) + (z+1)
      e = (y+1) + (z+1)
      if c % int(a[1]) == 0 and d % int(a[1]) == 0 and e % int(a[1]) == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, K = list(map(int, input().strip().split(" ")))
def check_N(a, b, c):
    if(((b+c)%K == 0) and ((a+c)%K==0)):
        return 1
    return 0
def numerize_list(a,b,c):
    if(a==b==c):
        return 1
    elif((a==b) or (b==c)):
        return 3
    else:
        return 6
    return 0
def count_list(a, b, c):
    if(check_N(a,b,c)):
        return numerize_list(a,b,c)
    return 0
ans = 0
for k in range(1,(2*N)//K+1):
    for a in range(1, N+1):
        b = k*K - a
        if(b<=N and a<=b):
            for c in range(b, N+1):
                ans += count_list(a, b, c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
""" this is C - Triangular Relationship"""

n, m = [int(i) for i in input().split()]

count = 0

for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            a = i+j
            b = j+k
            c = k+i
            if a%m == 0 and b%m == 0 and c%m == 0:
                if i == j and j == k:
                    count += 1
                elif i != j and j == k:
                    count += 3
                elif i == j and j != k:
                    count += 3
                else:
                    count += 6

print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(n, k):
    cnt = 0
    ptn = set()
    for a in range(1, n + 1):
        b = (k - a) % k

        while b <= a:
            if b > 0:

                c = (k - b) % k
                while c <= b:
                    if c > 0:
                        if (a + c) % k == 0:
                            # print(a, b, c, a + b, b + c, c + a)
                            if a == b == c:
                                cnt += 1
                            elif a == b or b == c or c == a:
                                cnt += 3
                            else:
                                cnt += 6
                    c += k
            b += k
    print(cnt)


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

# solve(3, 2)
# solve(5, 3)
# solve(31415, 9265)
# solve(35897, 932)

Submission status: Accepted

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

ans = 0
for i in range(1, n+1):
    a = ((i//k + 1)*k - i)
    if a <= n and (a * 2) % k == 0:
        p = (n - a) // k + 1
        ans = ans + p**2
print(ans)

Submission status: Accepted

Solution code:
from scipy.special import comb
# a = comb(n, r)
n,k=map(int,input().split())
p=n//k
q=p+1
ans=0
ans1 = (comb(p, 3, exact=True)+comb(p, 2, exact=True))*6+p
ans2 = (comb(q, 3, exact=True)+comb(q, 2, exact=True))*6+q
ans+=ans1
if k%2==0:
    if k*p+k//2>n:
        ans+=ans1
    else:
        ans+=ans2
# print(p)
# print(q)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num_list = list(range(1, n+1))
count = 0

if k % 2 == 1:
    count = (n // k) ** 3  

else:
    count = (n // k) ** 3  + ((n + k // 2) // k )** 3

print(count)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


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


def main():
    n, k = input_int_list()
    ans = 0
    if k % 2 == 0:
        # a,b,c == k//2 + p*k を満たすとき
        cnt = ((n - (k // 2)) // k) + 1
        ans += pow(cnt, 3)

    # a,b,c == p*k を満たすとき
    ans += pow(n // k, 3)

    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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

    # Kの倍数である数値の個数を数える
    a = 0
    for i in range(1, N + 1):
        if i % K == 0:
            a += 1

    # 余りがKの半分となる数値の個数を数える
    b = 0
    for i in range(1, N + 1):
        if i % K == K // 2:
            b += 1

    # 全ての要素がKの倍数の場合を足す
    ans = a * a * a
    if K % 2 == 0:
        # 全ての要素がK/2の場合を足す
        ans += b * b * b

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:

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

    A = [0] * K
    # a % K を決め打つと b % K, c % K のとるべき値が一意に決まることを利用します
    for i in range(1, N + 1):
        A[i % K] += 1

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

    print(res)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, K = MI()

    counter = cl.Counter()

    for i in range(1, N + 1):
        amari = i % K
        counter.update({amari: 1})

    pairs = []

    for i in range(K):
        if (i * 2) % K == 0:
            pairs.append(i)

    ans = 0

    for pair in pairs:
        count = counter[pair]
        ans += count ** 3

    print(ans)


main()

Submission status: Accepted

Solution code:
import sys
def input():
  return sys.stdin.readline().rstrip()

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

num_=[0]*K
for i in range(1,N+1):
  num_[i%K]+=1
ans=0
for a in range(K):
  b=(K-a)%K
  c=(K-a)%K
  if (b+c)%K!=0:
    continue
  ans+=num_[a]*num_[b]*num_[c]

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())

    cnt0 = cntk = 0
    for num in range(1, n + 1):
        if num % k == 0:
            cnt0 += 1
        elif num % k == k // 2:
            cntk += 1

    if k % 2 == 0:
        res = pow(cnt0, 3) + pow(cntk, 3)
    else:
        res = pow(cnt0, 3)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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)%k
    # print(am,nokori)
    if nokori*2%k==0:
        ans+=amari[nokori]**2
print(ans)

Submission status: Accepted

Solution code:
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    """
    x = a+b
    y = b+c
    z = a+c
    """
    N, K = read_ints()
    answer = 0
    for a in range(1, N+1):
        complement = K-(a%K)
        if 2*complement%K == 0:
            if N-complement >= 0:
                answer += ((N-complement)//K+1)**2
    return answer


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

mod_0_num = N//K

ans_mod_0 = mod_0_num**3
ans_mod_K = 0
if K%2 == 0:
    mod_K_num = (2*N-K)//(2*K) + 1
    ans_mod_K = mod_K_num**3

ans = ans_mod_0 + ans_mod_K
print(ans)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.special import comb

n, k = map(int, input().split())
cnt1 = 0
cnt2 = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,K=mint()
ans=pow(N//K,3)
if K%2==0:
    ans+=pow(max(0,(N-K//2)//K+1),3)
print(ans)

Submission status: Accepted

Solution code:
n,k=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:
    q= n//k 
    print(q**3);exit()
q=n//k 

qq=len([i for i in range(k//2,n+1,k)])
print(q**3+qq**3)

Submission status: Accepted

Solution code:
def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    N,K = map(int,input().split())
    
    #solve
    ans = 0
    for a in range(1,K+1):
        if a == K:
            b = K
            c = K
        else:
            b = K-a
            c = K-a
        if (a+b)%K == 0 and (b+c)%K == 0 and (a+c)%K == 0:
            ans+=((N-a)//K+1)*((N-b)//K+1)*((N-c)//K+1)
    print(ans)
    
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:
n, k = list(map(int, input().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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