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 itertools

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

comb = []
if K % 2 != 0:
    for a, b, c in itertools.product(range(1, N//K+1), range(1, N//K+1), range(1, N//K+1)):
        # print('odd:', a*K, b*K, c*K)
        comb.append((a, b, c))
else:
    for a, b, c in itertools.product(range(1, N//K+1), range(1, N//K+1), range(1, N//K+1)):
        # print('even_1:', a*K, b*K, c*K)
        comb.append((a, K, b, K, c, K))
    for a, b, c in itertools.product(range(1, (2*N+K)//(2*K)+1), range(1, (2*N+K)//(2*K)+1), range(1, (2*N+K)//(2*K)+1)):
        # print('even_2:', a*K-K//2, b*K-K//2, c*K-K//2)
        comb.append((a, K, 1, b, K, 1, c, K, 1))


print(len(set(comb)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = []
if K % 2 != 0:
    for a, b, c in itertools.product(range(1, N//K+1), range(1, N//K+1), range(1, N//K+1)):
        comb.append((a, b, c))
else:
    for a, b, c in itertools.product(range(1, N//K+1), range(1, N//K+1), range(1, N//K+1)):
        comb.append(((a, K), (b, K), (c, K)))
    for a, b, c in itertools.product(range(1, (2*N+K)//(2*K)+1), range(1, (2*N+K)//(2*K)+1), range(1, (2*N+K)//(2*K)+1)):
        comb.append(((a, K, 1), (b, K, 1), (c, K, 1)))


print(len(set(comb)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = []
if K % 2 != 0:
    for a, b, c in itertools.product(range(1, N//K+1), range(1, N//K+1), range(1, N//K+1)):
        comb.append((a, b, c))
else:
    for a, b, c in itertools.product(range(1, N//K+1), range(1, N//K+1), range(1, N//K+1)):
        comb.append((a*K, b*K, c*K))
    for a, b, c in itertools.product(range(1, (2*N+K)//(2*K)+1), range(1, (2*N+K)//(2*K)+1), range(1, (2*N+K)//(2*K)+1)):
        comb.append((a*K-K//2, b*K-K//2, c*K-K//2))


print(len(set(comb)))

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
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):
    #        print("a+b={} b+c={} c+a={}".format(i+j,j+k,i+k))
            if (i+j) % K == 0 and (j+k) % K ==0 and (i+k) % 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(n):
    a = k * (i+1)
    if a <= n:
        for ii in range(n):
            b = k * (ii+1)
            if b <= n:
                for iii in range(n):
                    c = k * (iii+1)
                    if c <= n:
                        ans = ans + 1
                        #print(a,b,c)
                    else:
                        break
            else:
                break
    else:
        break


if k % 2 == 0:
    for j in range(n):
        a = int(k/2) + k * j
        if a <= n:
            for jj in range(n):
                b = int(k/2) + k * jj
                if b <= n:
                    for jjj in range(n):
                        c = int(k/2) + k * jjj
                        if c <= n:
                            ans = ans + 1
                            #print(a,b,c)
                        else:
                            break
                else:
                    break
        else:
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
import itertools
ans = 0
for a, b, c in itertools.product(range(1,n+1), repeat=3):
  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 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 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 ((b+c) % K == 0):
                ans += 1
            else:
                continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
anslist= list(itertools.product([i for i in range(1,N+1)], repeat=3))
ans = 0
for alist in anslist:
    if (alist[0]+alist[1])%K==0 and (alist[1]+alist[2])%K==0 and (alist[2]+alist[0])%K==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
c=0
for i in range(1,N+1):
    ans=[0,0,0]
    for j in range(1,2*N//K+1):
        if 1<=j*K-i<=N:
            for l in range(1,2*N//K+1):
                if 1<=l*K-j*K+i<=N and (2*i+l*K-j*K)%K==0:
                    count=0
                    ans[0]=i
                    ans[1]=j*K-i
                    ans[2]=l*K-j*K+i
                    ans.sort()
                    c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
count = 0
list_abc = list(itertools.product(range(1,N+1),repeat = 3))
for i in list_abc:
  if (i[0] + i[1])%K==0 and (i[1] + i[2])%K==0 and (i[0] + i[2])%K==0:
    count = count +1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n, k = map(int, input().split())
a = []
x = k/2
count = 0
while x <= n:
    if x % 1 == 0:
        a.append(int(x))
    x += k/2
ori_list = list(itertools.product(a, repeat=3))
for i in range(len(ori_list)):
    if (ori_list[i][0] + ori_list[i][1]) % k == 0:
    	if (ori_list[i][1] + ori_list[i][2]) % k == 0:
    		if (ori_list[i][0] + ori_list[i][2]) % k == 0:
        		count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n, k = map(int, input().split())
a = []
x = k/2
while x <= n:
    if x % 1 == 0:
        a.append(int(x))
    x += k/2
ori_list = list(itertools.product(a, repeat=3))
for i in range(len(ori_list)):
    if (ori_list[i][0] + ori_list[i][1]) % k != 0:
        ori_list[i] = 'none'
    elif (ori_list[i][1] + ori_list[i][2]) % k != 0:
        ori_list[i] = 'none'
    elif (ori_list[i][0] + ori_list[i][2]) % k != 0:
        ori_list[i] = 'none'

while 'none' in ori_list:
    ori_list.remove('none')

print(len(ori_list))

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 (b+c) % k == 0 and (a+c) % k == 0:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  a = i+1
  for j in range(N):
    b = j+1
    if (a+b) % K == 0:
      for k in range(N):
        c = k+1
        if (b+c)%K==0 and (c+a)%K==0:
          cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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


MAX = int(2*N/K+1)

ans1=0
ans2=0
ans3=0

for alpha in range(1,MAX):
    for beta in range(alpha,MAX):
        for gamma in range(beta,MAX):
            a = K*(alpha-beta+gamma)
            b = K*(alpha+beta-gamma)
            c = K*(-alpha+beta+gamma)
            if(all([a>0,b>0,c>0]) and
            all([a<=N*2,b<=N*2,c<=N*2]) and
            all([a%2==0,b%2==0,c%2==0])
            ):
                if a==b and b==c:
                    ans1+=1
                elif a==b or b==c or c==a:
                    ans2+=1
                else:
                    ans3+=1

print(ans1+ans2*3+ans3*6)

Submission status: Time Limit Exceeded

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

ans=0

MAX = int(2*N/K+1)

for alpha in range(1,MAX):
    for beta in range(1,MAX):
        for gamma in range(1,MAX):
            a = K*(alpha-beta+gamma)
            b = K*(alpha+beta-gamma)
            c = K*(-alpha+beta+gamma)
            if(all([a>0,b>0,c>0]) and
            all([a<=N*2,b<=N*2,c<=N*2]) and
            all([a%2==0,b%2==0,c%2==0])
            ):
                ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

M = 6 * N // k
c = 0
dp = [[[-1 for _ in range(M+1)] for _ in range(M+1)] for _ in range(M+1)]

def check(l,m,n):
    a, b, c = k * (l+m-n) / 2, k * (m+n-l) / 2, k * (n+l-m) / 2
    return all([a.is_integer(), b.is_integer(), c.is_integer(), (a+b)%k==0, (b+c)%k==0, (c+a)%k==0, 0<a<=N, 0<b<=N, 0<c<=N])

for m in range(M+1):
    for i in range(1, m+1):
        for j in range(i, m+1):
            if dp[m][i][j] > 0:
                continue
            else:
                p = m - i - j
                if check(i,j,p):
                    s = len(set([i, j, p]))
                    if s == 1:
                        c += 1
                    elif s == 2:
                        c += 3
                    else:
                        c += 6

                    dp[m][i][j] = 1
                    dp[m][i][p] = 1
                    dp[m][j][i] = 1
                    dp[m][j][p] = 1
                    dp[m][p][i] = 1
                    dp[m][p][j] = 1

print(c)

Submission status: Time Limit Exceeded

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

M = 6 * N // k
c = 0
dp = [[[-1 for _ in range(M+1)] for _ in range(M+1)] for _ in range(M+1)]

def check(l,m,n):
    a, b, c = k * (l+m-n) / 2, k * (m+n-l) / 2, k * (n+l-m) / 2
    return all([a.is_integer(), b.is_integer(), c.is_integer(), (a+b)%k==0, (b+c)%k==0, (c+a)%k==0, 0<a<=N, 0<b<=N, 0<c<=N])

for m in range(M+1):
    for i in range(1, m+1):
        for j in range(1, m+1):
            if dp[m][i][j] > 0:
                continue
            else:
                p = m - i - j
                if check(i,j,p):
                    s = len(set([i, j, p]))
                    if s == 1:
                        c += 1
                    elif s == 2:
                        c += 3
                    else:
                        c += 6

                    dp[m][i][j] = 1
                    dp[m][i][p] = 1
                    dp[m][j][i] = 1
                    dp[m][j][p] = 1
                    dp[m][p][i] = 1
                    dp[m][p][j] = 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

# print(len(list(filter(lambda x: 2*x%K==0, range(1, N+1))))**2)
l = []
for i in range(1, N+1):
	if (2*i)%K == 0:
		l.append(i)
count = 0
for a, b, c in product(l, repeat=3):
	if (a+b)%K == (b+c)%K == (c+a)%K == 0:
		count += 1
print(count)

Submission status: Time Limit Exceeded

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

candidates = []
for i in range(1,N+1) :
	i = int(i)
	if (i % K == 0) :
		# Kの倍数は候補にする
		candidates.append(i)
		continue
	
	if (K % 2 == 0 and i % (K/2) == 0) :
		# Kが偶数だったらK/2も候補としてよい
		candidates.append(i)
		continue

count = 0
for a in candidates :
	for b in candidates :
		for c in candidates :
			if (int(a+b) % K == 0 and int(b+c) % K == 0 and int(c+a) % K == 0) :
				count += 1

print(count)

Submission status: Time Limit Exceeded

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

# 愚直に3重ループ
count = 0
for a in range(1,N+1) :
	for b in range(1, N+1) :
		for c in range(1, N+1) :
			if (int(a+b) % K == 0 and int(b+c) % K == 0 and int(c+a) % K == 0) :
				count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
n,k=list(map(int,input().split()))
l_n=[(v+1)%k for v in range(n)]
c = collections.Counter(l_n)
m = len(c)
ret=0
for i in range(0,m):
    for j in range(0,m):
        if (i+j)%k==0:
            for r in range(0,m):
                if (i+r)%k ==0 and (r+j)%k==0:
                    ret+=c[i]*c[j]*c[r]
print(ret)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
flag = 0
a = 1
while a <= N:
  b = 1
  while b <= a:
    c = 1
    while c <= b:
      if (a+b)%K == 0 and (b+c)%K == 0 and (c+a)%K == 0:
        if a == b and b == c:
          flag = flag + 1
        elif a == b or b == c or c == a:
          flag = flag + 3
        else:
          flag = flag + 6
      c = c + 1
    b = b + 1
  a = a + 1
print(flag)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int,input().split())
a = 1
b = 1
c = 1
x = 0
while a <= n:
    while b <= n:
        if (a + b) % k == 0:
            while c <= n:
                if (a + c) % k == 0 and (b + c) % k == 0:
                    x += 1
            c += 1
    b += 1
a += 1
print(x)

Submission status: Time Limit Exceeded

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

for i in range(1, N+1):
    j = K - i
    while j <= 0:
        j += K
    while j <= N:
        k = K - i
        while k <= 0:
            k += K
        while k <= N:
            if (j+k) % K == 0 and (j+k) != 0:
                counter += 1
            k += K
        j += K

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k=map(int,input().split())
aa=k/2
a=[]
b=[]
if k%2==0:
    for i in range(1,n+1):
        if i%k==0:
            a.append(i)
        elif i%k==aa:
            b.append(i)
else:
    for i in range(1,n+1):
        if i%k==0:
            a.append(i)
print(len(list(itertools.product(a,repeat=3)))+len(list(itertools.product(b,repeat=3))))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = list(map(int, input().split()))
count = 0
poss = [n for n in range(1, N+1) if (2*n)%K==0]

poss2 = list(itertools.product(poss, repeat=3))

count = len([comb for comb in poss2 if (comb[0]+comb[1])%K==0 and (comb[1]+comb[2])%K==0])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = list(map(int, input().split()))
count = 0
poss = [n for n in range(1, N+1) if (2*n)%K==0]

poss2 = list(itertools.product(poss, repeat=3))

def c(data):
    global count
    if (data[0]+data[1])%K==0 and (data[1]+data[2])%K==0:
        count += 1

for comb in poss2:
    c(comb)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = list(map(int, input().split()))
poss = []
count = 0
poss = [n for n in range(1, N+1) if (2*n)%K==0]

poss2 = list(itertools.product(poss, repeat=3))

for comb in poss2:
    if (comb[0]+comb[1])%K==0 and (comb[1]+comb[2])%K==0: #and (comb[2]+comb[0])%K==0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = list(map(int, input().split()))
poss = []
result = []
count = 0
for n in range(1, N+1):
    if (2 * n) % K == 0:
        poss.append(n)

#print(poss)
poss2 = list(itertools.product(poss, repeat=3))
#print(poss2)

for comb in poss2:
    if (comb[0]+comb[1])%K==0 and (comb[1]+comb[2])%K==0 and (comb[2]+comb[0])%K==0:
        count += 1

print(count)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
a = list(map(int,input().split()))
n = a[0]
x = a[1]
ans = 0
li = []
for i in range(n):
    li.append(i+1)
#print(li)

a3 = list(itertools.combinations_with_replacement(li, 3))
for i in a3:
    #print(str(i[0])+""+str(i[1])+""+str(i[2]))
    if (i[0]+i[1])%x==0 and (i[0]+i[2]) % x == 0 and (i[1]+i[2]) % x == 0:
        if i[0] == i[1] and i[1] == i[2]:
            ans += 1
        elif i[0] == i[1] or i[2] == i[1] or i[0] == i[2]:
            ans += 3
        else:
            ans += 6
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
if k % 2 == 0: o = int(k/2)
else:o = k
n1 = 0
n2 = 0
n3 = 0
for e in range(1,n // o + 2):
  a = o * e 
  for f in range(e,n // o  + 2):
    b = o * f 
    if (a + b) % k != 0 : continue
    for g in range(f,n // o + 2):
      c = o * g
      if (a + c)%k + (c + b)%k == 0:
        if a <= n and b <= n and c <= n:
          if a == b == c : n3 += 1
          elif a == b or b == c : n2 += 1
          else : n1 += 1
print( n1*3*2 + n2*3 + n3)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
if k % 2 == 0: o = int(k/2)
else:o = k
ans = 0
for e in range(1,n // o + 2):
  a = o * e 
  for f in range(1,n // o  + 2):
    b = o * f 
    if (a + b) % k != 0 : continue
    for g in range(1,n // o + 2):
      c = o * g
      if (a + b)%k + (a + c)%k + (c + b)%k == 0:
        if a <= n and b <= n and c <= n:
          ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
if k % 2 == 0: o = k/2
else:o = k
ans = 0
for e in range(1,int(n / o + 2)):
  a = o * e 
  for f in range(1,int(n / o  + 2)):
    b = o * f 
    if (a + b) % k != 0 : continue
    for g in range(1,int(n / o + 2)):
      c = o * g
      if (a + b)%k == 0 and  (a + c)%k == 0 and  (c + b)%k == 0:
        if a <= n and b <= n and c <= n:
          ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
if k % 2 == 0: o = k/2
else:o = k
ans = 0
for e in range(1,int(n / o + 2)):
  a = o * e 
  for f in range(1,int(n / o  + 2)):
    b = o * f 
    for g in range(1,int(n / o + 2)):
      c = o * g
      if (a + b)%k == 0 and  (a + c)%k == 0 and  (c + b)%k == 0:
        if a <= n and b <= n and c <= n:
          ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

v = 0
t = (2*N) // K

for i in range(1,t+1):
    if (K*i) % 2 == 0:
        if i % 2 == 1:
            for j in range(1,t+1,2):
                if (K*j) % 2 == 0:
                    for k in range(1,t+1,2):
                        if (K*k) % 2 == 0:
                            v += 1
        else:
            for j in range(2,t+1,2):
                if (K*j) % 2 == 0:
                    for k in range(2,t+1,2):
                        if (K*k) % 2 == 0:
                            v += 1
print(v)

Submission status: Time Limit Exceeded

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

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

print(v)

Submission status: Time Limit Exceeded

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

x = 0
y = 0
z = 0
cnt = 0

for a in range(1,n+1):
	for b in range(1,n+1):
		for c in range(1,n+1):
			x = a + b
			y = b + c
			z = c + a
			if x%k==0 and y%k==0 and z%k==0:
				cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
ans = []

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:
                cnt += 1
                ans.append([i,j,k])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
ans = []
inp = [int(x) for x in input().split()]

n = inp[0]
k = inp[1]

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.append([a, b, c])

print(len(ans))

Submission status: Time Limit Exceeded

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

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

Nlst = []
# for i in range(1,N+1):
#     Nlst.append(i)

if K % 2 == 0:
    for i in range(1,N+1):
        if i % K == 0 or i % (K/2) == 0:
            Nlst.append(i)
else:
    for i in range(1,N+1):
        if i % K == 0:
            Nlst.append(i)

tmplst = []
for i in itertools.product(Nlst, repeat=3):
    tmplst.append(i)

ans = 0

for (a,b,c) in tmplst:
    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:

iN , iK = [int(x) for x in input().split()]

iULimit = int( iN * 2  / iK )
iCount = 0
for i in range(1,iULimit+1):
    for j in range(1,iULimit + 1):
        for m in range(1,iULimit + 1):
            if( 0 < i + j - m and 0 < i -j + m and 0 < -i + j + m and i + j - m <= iULimit and i-j+m <= iULimit and -i+j+m <= iULimit):
                if( (i + j - m ) * iK % 2 == 0 and (i -j + m) * iK % 2 == 0 and ( -i + j + m) * iK % 2 ==0 ):
                    iCount = iCount + 1
print (iCount)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().strip().split())
result = 0
num = N // K
result += num
if num == 2:
    result += num * (num - 1) * 3
elif num > 2:
    result += num * (num - 1) * 3
    result += num * (num - 1) * (num - 2)


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(a, N + 1, K):
            for c in range(b, N + 1, K):
                if a == b and b == c:
                    result += 1
                elif a == b or b == c:
                    result += 3
                else:
                    result += 6
    print(result)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().strip().split())
result = 0
for a in range(K, N+1, K):
    for b in range(a, N + 1, K):
        for c in range(b, N + 1, K):
            if a == b and b == c:
                result += 1
            elif a == b or b == c:
                result += 3
            else:
                result += 6

if K % 2 == 1:
    print(result)
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(a, N + 1, K):
            for c in range(b, N + 1, K):
                if a == b and b == c:
                    result += 1
                elif a == b or b == c:
                    result += 3
                else:
                    result += 6
    print(result)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().strip().split())
result = 0
for a in range(K, N+1, K):
    for b in range(a, N + 1, K):
        for c in range(b, N + 1, K):
            if a == b and b == c:
                result += 1
            elif a == b or a == c or b == c:
                result += 3
            else:
                result += 6


if K % 2 == 1:
    print(result)
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(a, N + 1, K):
            for c in range(b, N + 1, K):
                if a == b and b == c:
                    result += 1
                elif a == b or a == c or b == c:
                    result += 3
                else:
                    result += 6
    print(result)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().strip().split())
count = set()
for a in range(K, N+1, K):
    for b in range(K, N + 1, K):
        for c in range(K, N + 1, K):
            count.add((a, b, c))

if K % 2 == 1:
    print(len(count))
else:
    start = K // 2
    for a in range(start, N + 1, K):
        for b in range(start, N + 1, K):
            for c in range(start, N + 1, K):
                count.add((a, b, c))
    print(len(count))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().strip().split())
count = set()
for a in range(1, N+1):
    if a % K == 0:
        for b in range(K, N + 1, K):
            for c in range(K, N + 1, K):
                count.add((a, b, c))
    else:
        start = K - a % K
        for b in range(start, N + 1, K):
            for c in range(start, N + 1, K):
                if (b + c) % K == 0:
                    count.add((a, b, c))
print(len(count))

Submission status: Time Limit Exceeded

Solution code:
import itertools

x,y = map(int,input().rstrip().split())


kk = [ i for i in itertools.product(range(1,x+1), repeat=3) if (i[0]+i[1])%y == 0 and (i[1]+i[2])%y == 0 and (i[2]+i[0])%y == 0]

print(len(kk))

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 (a+b)%k == 0:
        if (b+c)%k == 0:
          if (c+a)%k ==0:
            count += 1
        
print(count)

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 (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:
#-*- coding = utf-8 -*-
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 (a+b)%k ==0:
                if (b+c)%k ==0:
                    if (c+a)%k==0:
                        count += 1
print (count)

Submission status: Time Limit Exceeded

Solution code:
def logic(N, K):
    if K == 1:
        return N**3
    count = 0
    for a in range(1, N + 1):
        b_s = K - (a % K)
        for b in range(b_s, N + 1, K):
            for c in range(b_s, N + 1, K):
                if (b + c) % K == 0:
                    count += 1
    return count

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def logic(N, K):
    count = 0
    for a in range(1, N + 1):
        b_s = K - (a % K)
        for b in range(b_s, N + 1, K):
            for c in range(b_s, N + 1, K):
                if (b + c) % K == 0:
                    count += 1
    return count

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,k = [int(i) for i in input().split(' ')]
sum = 0
for p in range(1, n+1):
  for q in range(1, n+1):
    for r in range(1, n+1):
      if (p+q)%k==0 and (q+r)%k==0 and (r+p)%k==0:
        sum+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N,K = (int(i) for i in input().split()) #標準入力
count = 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 and (c+a)%K==0:
                    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,K = (int(i) for i in 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 (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:
# encoding: utf-8
N, K = map(int, input().split())

ans = 0

# 2 * (a + b + c) = K * (p + q + r)
for pqr in range(3, (6 * N) // K + 1):
    # a + b + c = ?
    if (pqr * K) % 2: continue
    else: abc = (pqr * K) // 2
    for p in range(max((1, -((N - abc) // K))), abc // K + 1):
        qr = pqr - p
        min_r = -((p * K - 2 * abc) // (2 * K))
        max_r = min(((2 * abc) // K - 2 * p, (abc - 1) // K))
        # count w/o r loop
        if min_r > max_r: continue
        # print(abc, (p, qr - min_r, min_r), (p, qr - max_r, max_r))
        ans += (max_r - min_r + 1) * 6
        if p == qr - min_r == min_r: ans -= 5 # p = q = r
        if p < qr - min_r == min_r: ans -= 3 # p < q = r
        if p == qr - max_r < max_r: ans -= 3 # p = q < r
            
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

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

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

print(ans)

Submission status: Time Limit Exceeded

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

results = set()

for a in range(1, N + 1):
    for bn in range(1, 10000):
        b = (bn * K) - a
        if b < 1:
            continue
        elif b > N:
            break
        for cn in range(1, 10000):
            c = (cn * K) - a
            if c < 1:
                continue
            elif c > N:
                break

            if (b + c) % K != 0:
                continue

            results.add((a, b, c))

print(len(results))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# N, K = 3, 2

if K % 2 != 0:
    ans = (N // K)**3
else:
    full = []
    for i in range(K, N+1, K):
        full.append(i)
    # print(full)
    ans = len(full) ** 3

    half = []
    for i in range(int(K/2), N+1, int(K/2)):
        half.append(i)
        half = list(set(half) - set(full))
    # print(half)
    ans += len(half) ** 3


print(ans)