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:
from collections import defaultdict
n, k = map(int, input().split())
m = (2*n)//k
P = defaultdict(list)
for a in range(1, n+1):
    for i in range(1, m+1):
        b = i*k - a
        if b > n or b < 1:
            continue
        P[a].append(b)
#print(P)
cnt = 0
for a in range(1, n+1):
    for i in range(1, m+1):
        b = i*k - a
        if b > n or b < 1:
            continue
        for c in P[a]:
            if (b + c) % k == 0:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
seq = list(range(1,N + 1))
cand = list(itertools.product(seq, repeat=3))
ans = 0
for c in cand:
  ab = c[0] + c[1]
  bc = c[1] + c[2]
  ca = c[2] + c[0]
  if ab % K == 0 and bc % K == 0 and ca % K == 0:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
listA=list(map(int,input().split()))
N=listA[0]
K=listA[1]
nk=int(2*N/K)
S=0
for x in range(1,nk+1):
    for y in range(1,nk+1):
        for z in range(1,nk+1):
            if(K%2==1):
                if((1<=x-y+z)&(x-y+z<=nk)&((x-y+z)%2==0)):
                    if((1<=x-z+y)&(x-z+y<=nk)&((x-z+y)%2==0)):
                        if((1<=y-x+z)&(y-x+z<=nk)&((y-x+z)%2==0)):
                            S+=1
                            
            else:
                if((1<=x-y+z)&(x-y+z<=nk)):
                    if((1<=x-z+y)&(x-z+y<=nk)):
                        if((1<=y-x+z)&(y-x+z<=nk)):
                            S+=1
                
print(S)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
result = 0
for i in range(N):
        for v in range(N):
            for r in range(N):
                if (((i + 1) + (v + 1)) % K == 0) & (((i + 1) + (r + 1)) % K == 0) & (((v + 1) + (r + 1)) % K == 0):
                    result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = map(int, input().split())
a = int(n/k)
if(a < 2):
    b = 0
else:
    b = math.factorial(a) // (math.factorial(a - 2) * math.factorial(2))
if(a < 3):
    c = 0
else:
    c = math.factorial(a) // (math.factorial(a - 3) * math.factorial(3))
ans = a + b * 6 + c * 6
if(k % 2 == 0):
    t = int(k / 2)
    if(a * k + t > n):
      ans = ans * 2
    else:
      d = a + 1
      if(d < 2):
          e = 0
      else:
          e = math.factorial(d) // (math.factorial(d - 2) * math.factorial(2))
      if(d < 3):
          f = 0
      else:
          f = math.factorial(d) // (math.factorial(d - 3) * math.factorial(3))
      ans += (d + e * 6 + f * 6)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# encoding: utf-8
N, K = map(int, input().split())

ans = 0
pqr = 3
while pqr * K <= 6 * N:
    for r in filter(lambda x: pqr - x > x, range(pqr // 3, pqr)):
        pq = pqr - r
        if r * K > 2 * N: break
        for p in range(pq - r, (pq // 2) + 1):
            q = pq - p
            if p > q: break
            elif q * K > 2 * N: continue
            elif p * K > 2 * N: break
            elif (q + r - p) * K > 2 * N: continue
            elif (r + p - q) * K > 2 * N: break
            elif (q + r - p) * K % 2: continue
            elif (r + p - q) * K % 2: continue
            # print(p, q, r)
            if p == q == r: ans += 1
            elif p < q < r: ans += 6
            else: ans += 3
    pqr += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

ans=0
j=2
l=1

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

if k%2==0:
    for i in range(1,n+1):
        a=k-i
        while a<1:
            a+=k
        c=a
        while a<=n:
            b=c
            while a+b<k:
                b+=k
            if (a+b)%k==0:
                while b<=n:
                    ans+=1
                    b+=k
            a+=k    
    
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
val = input().split()
a, b = [int(i) for i in val]

res = 0

for i in range(1, a+1):
    for j in range(1, a+1):
        if (i+j) % b != 0:
            continue
        for k in range(1, a+1):
            if (i+k) % b != 0:
                continue
            if (j+k) % b != 0:
                continue
            res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
count=0
for p in range(1,n+1):
    for q in range(1,n+1):
        for r in range(1,n+1):
            a=p+q
            b=q+r
            c=r+p
            if a%k==0 and b%k==0 and c%k==0:
                count+=1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
input = input().split()
N = int(input[0])
K = int(input[1])
target = K
counter = 0

for i in range(1,N+1):
    # print("******")
    # print(i)
    # print("------")
    n1 = i
    multiple1 = K
    while(multiple1 < N*2+1):
        n2 = multiple1 - i
        multiple1 += K
        if(n2<N+1 and n2>0):

            multiple2 = K
            while(multiple2 < N*2+1):
                n3 = multiple2 - n2
                multiple2 += K
                if((n1+n3)%K == 0 and n3>0 and n3<N+1):
                    counter += 1
                    # print(n1, end="")
                    # print(" ", end="")
                    # print(n2, end="")
                    # print(" ", end="")
                    # print(n3, end="")
                    # print(" ")
                    # print("success")
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
N,K=map(int,input().split(" "))

end=int(2*N/K)
A=list(it.product(range(1,end+1,1),range(1,end+1,1)))
ans=0
for i in range(len(A)):
    for a in range(1,N+1,1):
        if A[i][1]*K-a<=N and a<A[i][1]*K and A[i][0]*K-a<=N and a<A[i][0]*K:
            b=A[i][0]*K-a
            c=A[i][1]*K-b
            if (a+c)%K==0:
                ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n, k = map(int, input().split())
a = int(n/k)
if(a < 2):
    b = 0
else:
    b = math.factorial(a) // (math.factorial(a - 2) * math.factorial(2))
if(a < 3):
    c = 0
else:
    c = math.factorial(a) // (math.factorial(a - 3) * math.factorial(3))
ans = a + b * 6 + c * 6
if(k % 2 == 0):
    t = int(k / 2)
    if(a * k + t > n):
      d = a
    else:
      d = a+ 1


    if(d < 2):
        e = 0
    else:
        e = math.factorial(d) // (math.factorial(d - 2) * math.factorial(2))
    if(d < 3):
        f = 0
    else:
        f = math.factorial(d) // (math.factorial(d - 3) * math.factorial(3))
    ans += (d + e * 6 + f * 6)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# encoding: utf-8
N, K = map(int, input().split())

ans = 0
pqr = 3
while pqr * K <= 6 * N:
    for r in filter(lambda x: pqr - x > x, range(1, pqr)):
        pq = pqr - r
        if r * K > 2 * N: break
        for p in range(pq - r, (pq // 2) + 1):
            q = pq - p
            if p > q: break
            elif q * K > 2 * N: continue
            elif p * K > 2 * N: break
            elif (q + r - p) * K > 2 * N: continue
            elif (r + p - q) * K > 2 * N: continue
            elif (q + r - p) * K % 2: continue
            elif (r + p - q) * K % 2: continue
            # print(p, q, r)
            if p == q == r: ans += 1
            elif p < q < r: ans += 6
            else: ans += 3
    pqr += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for a in range(1, n+1):
    bran = [x for x in range((a//k+1)*k-a,n+1,k) if a<=x]
    #print(a,bran)
    for b in bran:
        cran = [x for x in range((b//k+1)*k-b,n+1,k) if b<=x]
        #print(b,cran)
        for c in cran:
            if (a+c)%k == 0:
                #print(a,b,c)
                #print("***",(a+b)/k, (b+c)/k, (c+a)/k)
                pair = set([a,b,c]) 
                if len(pair)==1:
                    count += 1
                elif len(pair)==2:
                    count += 3
                else:
                    count += 6
                #print("+",count)
print(count)

Submission status: Time Limit Exceeded

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

result = []

a = 1
b = 1
c = 1

while(a <= N):
  b = 1
  while(b <= N):
    if a % K == 0:
      if b % K != 0:
        b += K - (b % K)
        if b > N:
          continue
    else:
      if (a + b) % K != 0:
        b += (K - ((a + b) % K))
        if b > N:
          continue
    c = 1
    while(c <= N):
      if a % K == 0:
        if c % K != 0:
          c += (K - (c % K))
          if c <= N:
          	result.append([a, b, c])
        else:
          result.append([a, b, c])
      else:
        if (a + c) % K == 0:
          if (b + c) % K == 0:
            result.append([a, b, c])
        else:
          c += (K - ((a + c) % K))
          if c <= N:
            if (c + b) % K == 0:
              result.append([a, b, c])
      c += 1
    b += 1
  a += 1

print(len(result))

Submission status: Time Limit Exceeded

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

import itertools

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

p = list(itertools.product(range(1,N+1), repeat=3))

ans = 0
for pair in p:
    if (pair[0] + pair[1]) % K == 0 and (pair[1] + pair[2]) % K == 0 and (pair[2] + pair[0]) % K == 0:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
ll = 2*n // k
ans = 0
for i in range(1, ll+1):
    for j in range(1, ll+1):
        for m in range(1, ll+1):
            if ((m+i-j)*k) % 2 == 0 and ((i-m+j)*k) % 2 == 0 and ((m-i+j)*k) % 2 == 0:
                if (m+i-j) > 0 and (i-m+j) > 0 and (m-i+j) > 0:
                    if (m+i-j)*k//2 <= n and (i-m+j)*k//2 <= n and (m-i+j)*k//2 <= n:
                        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

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

    '''
    for i in range(k, n+1, k):
        for j in range(k, n+1, k):
            if (i + j) % k == 0:
                for m in range(k, n+1, k):
                    if (i+m) % k == 0 and (j+m) % k == 0:
                        print(i, j, m)
    '''
    # kは奇数
    if k % 2 == 1:
        print((n // k) ** 3)
        return

    c = 0
    for i in range(k//2, n+1, k//2):
        for j in range(k//2, n+1, k//2):
            if (i + j) % k == 0:
                for m in range(k//2, n+1, k//2):
                    if (i+m) % k == 0 and (j+m) % k == 0:
                        #print(i, j, m)
                        c += 1

    # kは偶数
    print(c)

main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

def solve():
  n, k = map(int, input().split())
  count = 0
  # # A解法
  # for a in range(1, n+1):
  #   for b in range(1, n+1):
  #     # for c in range(1, n+1):
  #     count += min(a, cal(a, b, 3, n, k))

  # B解法
  ary = [(a, b, c)
    for a in range(1, n+1)
    for b in range(1, n+1)
    for c in range(1, n+1)]
  # print(ary)

  for i in range(len(ary)):
    A = ary[i][0] + ary[i][1]
    B = ary[i][1] + ary[i][2]
    C = ary[i][0] + ary[i][2]

    if A%k ==0 and B%k ==0 and C%k ==0:
      count += 1


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

  # C解法
  # a = range(1, n+1)
  # for i in range(1, n+1):
  #   b = i


  
  print(count)


solve()

Submission status: Time Limit Exceeded

Solution code:
max_num, target = list(map(int, input().split()))

count = 0

# 次の数の候補をあらかじめ保持する
next_num_list = [set([]) for i in range(max_num)]

# 候補リスト生成
for i in range(1, max_num+1):
    for m in range(target, 2*max_num + 1, target):
        if i + max_num >= m and m - i > 0:
            next_num_list[i-1].add(m-i)

# 検査
for i in range(1, max_num+1):
    for j in next_num_list[i-1]:
        for k in next_num_list[j-1]:
            # [k-1]のsetにiが入って入ればおk
            if i in next_num_list[k-1]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def abc108_c():
    import sys
    import numpy as np
    input = sys.stdin.readline

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

    count = 0
    ks = np.array([i * k for i in range(1, (3 * n) // k + 1)])

    for a in range(1, n + 1):
        tmp = ks - a
        b_candidate = tmp[(1 <= tmp) & (tmp <= n)]
        c_candidate = b_candidate
        for b in b_candidate:
            count += np.sum((b + c_candidate) % k == 0)

    return count


print(abc108_c())

Submission status: Time Limit Exceeded

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

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(i,N+1):
        
        for k in range(j,N+1):
            if (i+j)%K==0 and (j+k)%K==0 and (k+i)%K==0:
                if i==j and j==k:
                    count+=1
                else:
                    count+=3
                
                
                
                
                
print(count)

Submission status: Time Limit Exceeded

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

import numpy as np
import itertools

k_baisu = np.arange(K, 2*N + 1, K)

ans = 0

for a in range(1,N+1):
    tmp = k_baisu - a
    tmp = tmp[(tmp > 0) & (tmp <= N)]
    for b, c in itertools.product(tmp, repeat=2):
        if b + c in k_baisu:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
def main():
	n = list(map(int, input().split()))
	N = n[0]
	K = n[1]
	c = 0
	for i in range(N):
		for j in range(i,N):
			for k in range(j,N):
				if (i + j + 2) % K == 0:
					if (j + k + 2) % K == 0:
						if (k + i + 2) % K == 0:
							if i == j and j == k:
								c1 = 1
							elif i == j or j == k or k == i:
								c1 = 3
							else:
								c1 = 6 
							c += c1
							c1 = 0
	print(c)


if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
N,K=map(int,input().split(" "))

end=int(2*N/K)
A=list(it.product(range(1,end+1,1),range(1,end+1,1)))
ans=0
for i in range(len(A)):
    for a in range(1,N+1,1):
        b=A[i][0]*K-a
        c=A[i][1]*K-b
        if 0<b and b<=N and 0<c and c<=N and (a+c)%K==0:
            ans+=1



print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
lmnk=(2*N//K)
ans=0
for h in range(2//K,lmnk+1):
    a=h*K//2
    if 1<=a<=N:
        for i in range((1+a)//K,(N+a)//K+1):
            b=i*K-a
            if 1<=b<=N:
                for j in range((1+b)//K,(N+b)//K+1):
                    c=j*K-b
                    if 1<=c<=N and (c+a)%K==0:
                            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

p = 0

for a in range(1, n+1):
    for b in range(a, n+1):
        if not (a+b)%k == 0:
            pass
        else:
            for c in range(b, n+1):
                if (b+c)%k == 0 and (c+a)%k == 0:
                    if a == b and b == c:
                        p += 1
                    elif a == b and not b == c:
                        p += 3
                    elif not a == b and  b == c:
                        p += 3
                    else:
                        p += 6
              
print( p )

Submission status: Time Limit Exceeded

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

z = 0
std = 1
if K%2 == 0:
    std = int(K/2)
else:
    std = K
for a in range(std,N+1,std):
    for b in range(std,N+1,std):
        for c in range(std,N+1,std):
            if (a+b)%K == 0 and (b+c)%K ==0 and (c+a)%K==0:
                z= z+1
print(z)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
lmnk=(2*N//K)
ans=0
for h in range(1,lmnk+1):
    a=h*K//2
    if 1<=a<=N:
        for i in range((1+a)//K,(N+a)//K+1):
            b=i*K-a
            if 1<=b<=N:
                for j in range((1+b)//K,(N+b)//K+1):
                    c=j*K-b
                    if 1<=c<=N and (c+a)%K==0:
                            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
cmb = []
cnt = 0
for a in range(1,K+1):
  for b in range(K-a, N+1, K):
    if b < a: continue
    for c in range(K-a, N+1, K):
      if c < b: continue
      if (b+c) % K == 0:
        for a2 in range(a, N+1, K):
          if b < a2: continue
          if   a2==b and b==c: cnt += 1
          elif a2==b and b!=c: cnt += 3
          elif a2!=b and b==c: cnt += 3
          elif a2!=b and b!=c: cnt += 6
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N, K = [int(i) for i in input().split()]
N = [i + 1 for i in range(N)]

count = 0
for c in product(N, repeat=3):
    if (c[0] + c[1]) % K == 0:
        if (c[1] + c[2]) % K == 0:
            if (c[2] + c[0]) % K == 0:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

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 k in range(1,N+1):
            if (i+j)%K==0 and (j+k)%K==0 and (k+i)%K==0:
                count+=1
                
                
                
                
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*-coding:utf-8-*-
N, K = map(int, input().split(" "))

ans = 0

for a in range(1, N+1):
    for b in range(K-a, N+1) if a < K else range(1,N+1):
        if (a+b)%K != 0:
            continue
        for c in range(K-a, N+1) if a < K else range(1,N+1):
            if (b+c)%K == 0 and (c+a)%K == 0:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools as itr

N, K = tuple(int(i) for i in input().split())

n = int(N/K)
c1 = list(itr.product(range(n), repeat=3))
c1 = len(c1)

k_2 = K/2

if N < k_2:
    print(0)
elif K%2 != 0:
    print(c1)
else:

    if N < n*K + k_2:
        c2 = list(itr.product(range(n), repeat=3))
    else:
        c2 = list(itr.product(range(n+1), repeat=3))

    c2 = len(c2)
    print(c1 + c2)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
lmnk=(2*N//K)
ans=0
for h in range(1,lmnk+1):
    a=h*K//2
    if 1<=a<=N:
        for i in range(1,(N+a)//K+1):
            b=i*K-a
            if 1<=b<=N:
                for j in range(1,(N+b)//K+1):
                    c=j*K-b
                    if 1<=c<=N:
                        if (a+b)%K==0 and (b+c)%K==0 and (c+a)%K==0:
                            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

list = []
p = 0

for a in range(1,n+1):
    x = int(a/k)
    y = int((n+a)/k)
    for i in range(x+1,y+1):
            if  (i*k-a+i*k-a) % k ==0:
                p = p + (y-x)
            else:
                pass

print(p)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
s = [[a, b, c] 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(len(s))

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):
        for c in range(1,N+1):
            if ((a + b) % K== 0) and ((a + c) % K== 0) and ((c + b) % K== 0):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
lmnk=(2*N//K)
ans=0
for h in range(1,lmnk+1):
    a=h*K//2
    if 1<=a<=N:
        for i in range(1,lmnk+1):
            b=i*K-a
            if 1<=b<=N:
                for j in range(1,lmnk+1):
                    c=j*K-b
                    if 1<=c<=N:
                        if (a+b)%K==0 and (b+c)%K==0 and (c+a)%K==0:
                            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

N,K=map(int,input().split())
total = 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:
                total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
n, k = list(map(int, input().split()))
ans = 0
for i in range(n+1):
    if i == 0:
        continue
    for j in range(n+1):
        if j == 0:
            continue
        if ((i + j) % k != 0):
            continue
        for h in range(n+1):
            if h == 0:
                continue
            if ((j + h) % k == 0) and ((h + i) % k == 0):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*-coding:utf-8-*-
N, K = map(int, input().split(" "))

ans = 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:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

def solve():
  n, k = map(int, input().split())
  count = 0
  # A解法
  for a in range(n):
    a += 1
    for b in range(n):
      b += 1
      for c in range(n):
        c += 1
        if (a+b)%k == 0 and (b+c)%k == 0 and (c+a)%k == 0:
          count += 1

  # B解法
  # ary = [(a, b, c)
  #   for a in range(n)
  #   for b in range(n)
  #   for c in range(n)]
  
  # for a, b, c in ary:
  #   if (a+b)%k == 0 and (b+c)%k == 0 and (c+a)%k == 0:
  #     count += 1

  # C解法
  # a = range(1, n+1)
  # for i in range(1, n+1):
  #   b = i


  
  print(count)


solve()

Submission status: Time Limit Exceeded

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

cnt = 0
for a in range(1,n+1):
    if (2*a) % k == 0:
        for b in range(a,n+1):
            if ((2*b) % k == 0)and((a+b) % k == 0 )and((a-b) % k == 0 ):
                for c in range(b,n+1):
                    if ((2*c) % k == 0)and((a+c) % k == 0 )and((c+b) % k == 0 ):
                        if (a==b)and(b==c):
                            cnt += 1
                        elif (a!=b)and(b!=c)and(a!=c):
                            cnt += 6
                        else:
                            cnt +=3
                        
                        

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input = input().split()
N = int(input[0])
K = int(input[1])
sum = 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:
                sum += 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N,K = (int(i) for i in input().split())
ans=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:
                ans +=1
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
minus = []
for i in range(1,N+1):
    
    a = i
    b = i
    c = i
    if (a + b) % K == 0:
        count += 1
        count += len(minus) * (3*2)
        if len(minus) >= 2:
            kumiawase = math.factorial(len(minus))/(math.factorial(len(minus)-2)*math.factorial(2))
            count += kumiawase * (3*2)
    if i % K == 0:
        minus.append(i)

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import math
s = input().split()
N = int(s[0])
K = int(s[1])

ct = 0

u = math.ceil(2*N/K)

def cond_e(a, b, c):
  if a+b-c > 0 and a-b+c > 0 and -a+b+c > 0 and a+b-c <= 2*N/K and a-b+c <= 2*N/K and -a+b+c <= 2*N/K:
    return True
  else:
    return False
  
def cond_o(a, b, c):
  if a+b-c > 0 and a-b+c > 0 and -a+b+c > 0 and a+b-c <= 2*N/K and a-b+c <= 2*N/K and -a+b+c <= 2*N/K and (a+b-c)%2 == 0 and (a-b+c)%2 == 0 and (-a+b+c)%2 == 0:
    return True
  else:
    return False

for a in range(1,u+1):
  for b in range(1,u+1):
    for c in range(1,u+1):
      if K%2 == 0 and cond_e(a, b, c):
        ct += 1
      elif K%2 != 0 and cond_o(a, b, c):
        ct += 1

print(str(ct))

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8


INF = float('inf')


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


N, K = inpl()

A = [i + 1 for i in range(N)]

ans = 0
for a in A:
    if (2 * a) % K != 0: continue
    if a == K:
        mod = 0
    elif a > K:
        mod = abs(K - a) % K
    else:
        mod = a
    X = [x for x in A if (x + mod) % K == 0]
    if a in X: ans += len(X) ** 2
print(ans)

Submission status: Time Limit Exceeded

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

import numpy as np
# t = time.time()
ans = 0
mut_ori = n//k
for a in range(1, k + 1):
    b_cand = list(range(k - a%k,n+1,k))
    for b in b_cand:
        c_cand = list(range(k - b%k,n+1,k))
        for c in c_cand:
            if a <= n%k:
                mut = mut_ori + 1
            else:
                mut = mut_ori
            if (a + c) % k == 0:
                ans += mut
#             print(a,b,c,mut)
print(ans)
# print(time.time() - t)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
count=0
for a in range(1,N+1):
  for b in range(1,N+1):
    for c in range(1,N+1):
      if 2*(a+b+c)%K==0:
        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:
def calc(n, k, x):
    c = 0

    while x <= n:
        y = z = x

        while 0 < y:
            z = y

            while 0 < z:
                if x == y and y == z:
                    c += 1
                elif x == y or y == z:
                    c += 3
                else:
                    c += 6

                z -= k

            y -= k

        x += k

    return c

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

if k % 2 == 0:
    print(calc(n, k, k) + calc(n, k, k // 2))
else:
    print(calc(n, k, k))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
n_division = 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:
                n_division += 1
print(n_division)

Submission status: Time Limit Exceeded

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

cnt = 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):
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        if (i+j)%k != 0:
            continue
        for a in range(1,n+1):
            if (j+a)%k == 0 and (a+i)%k == 0:
                c += 1
            else:
                continue

print(c)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
numbers = [x for x in range(1,N+1)]
a = 0
for i in numbers:
    for j in numbers:
        for k in numbers:
            if (i+j) % K == 0 and (i+k) % K == 0 and (k+j) % K == 0:
                a += 1
            else:
                pass
print(a)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
N,K=map(int,input().split(" "))

M=list(range(1,N+1,1))
al=list(it.product(M,M,M))

ans=0

for i in range(len(al)):
    if (al[i][0]+al[i][1])%K==0 and (al[i][1]+al[i][2])%K==0 and (al[i][2]+al[i][0])%K==0:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

p = 0
list = list(range(1, n+1))

for a in list:
    for b in list:
        for c in list:
            if (a+b)%k == 0 and (b+c)%k == 0 and (c+a)%k == 0:
                p += 1
            else:
                pass
              
print( p )

Submission status: Time Limit Exceeded

Solution code:
n, k= map(int,input().split())
a = [[a,b,c] 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 == (b+c)%k == (c+a)%k == 0]
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n,K = map(int,input().split())
c = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            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 = (int(i) for i in input().split())
a = 0
b = 0
c = 0
count = 0
for i in range(N):
    a = i+1
    for j in range(N):
        b = j + 1
        for k in range(N):
            c = k + 1
            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:
n, k = map( int, input().split() )

p = 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:
                p += 1
            else:
                pass
              
print( p )