Problem:


Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692



Sample input:
2


Sample output:
9

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())

r = 0
g = 0
b = 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
ans = r * b * g

d = 1
while True:
    if 2 * d >= N:
        break
    i = 0
    while True:
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
        i += 1
    d += 1

print(ans)

Submission status: Runtime Error

Solution code:
k=int(input())
d=0
for a in range(1,k+1) :
    for b in range(1,k+1):
        i=gcd(a,b)
        for c in range(1,k+1):
            d+=gcd(i,c)
print(d)

Submission status: Runtime Error

Solution code:
def gcd_list(numbers):
    return reduce(gcd, numbers)

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #l = sorted([i, j, k])
            #l = [i, j, k]
            #a, b, c = l[0], l[1], l[2]
            a, b, c = i, j, k
            if memo[a][b][c] != -1:
                ans += memo[a][b][c]
            else:
                memo[a][b][c] = gcd_list([a, b, c])
                memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
                ans += memo[a][b][c]
            #ans += gcd_list([i, j, k])


print(ans)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
C=0
 
for l in range(N):
    for n in range(N):
        for m in range(N):
            if l==0 or m==0 or n==0:
                C+=1
            else:
                C+=math.gcd(math.gcd(l+1,m+1),n+1)
 
print(C

Submission status: Runtime Error

Solution code:
from math import gcd
k = int(input())
ans = 0

for s in range(1,k+1):
	for t in range(1,k+1):
  		for u in range(1, k+1):
			ans += gcd(gcd(s,t),u)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
 
def gcb(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        gcb_table[a][b] = a
    else:
        if gcb_table[a][b] == -1:
            gcb_table[a][b] = gcb(b, a%b)
    return gcb_table[a][b]

k = int(input())
gcb_table = [[-1 for _ in range(k+1)] for _ in range(k+1)]

for i in range(1, k+1):
    for j in range(1, k+1):
        temp = gcb(i, j)
        gcb_table[i][j] = temp
        gcb_table[j][i] = temp
        
res = 0
l_k = range(1, k+1)
for part in itertools.product(l_k, l_k, l_k):
    gcb_first = gcb_table[part[0]][part[1]]
    res += gcb_table[gcb_first][part[2]]
print(res)

Submission status: Runtime Error

Solution code:
from itertools import product
 
def gcb(a, b):
  	if a < b:
      	a, b = b, a
    if b == 0:
        gcb_table[a][b] = a
    else:
        if gcb_table[a][b] == -1:
            gcb_table[a][b] = gcb(b, a%b)
    return gcb_table[a][b]
  
k = int(input())
gcb_table = [[-1 for _ in range(k+1)] for _ in range(k+1)]
 
for i in range(1, k+1):
    for j in range(1, k+1):
        temp = gcb(i, j)
        gcb_table[i][j] = temp
        gcb_table[j][i] = temp
        
res = 0
l_k = range(1, k+1)
for part in itertools.product(l_k, l_k, l_k):
    gcb_first = gcb_table[part[0]][part[1]]
    res += gcb_table[gcb_first][part[2]]
print(res)

Submission status: Runtime Error

Solution code:
from itertools import product
 
def gcb(a, b):
    if b == 0:
        gcb_table[a][b] = a
    else:
        if gcb_table[a][b] == -1:
            gcb_table[a][b] = gcb(b, a%b)
    return gcb_table[a][b]

def gcb_3(a, b, c):
    return gcb(gcb(a, b), gcb(b, c))
  
k = int(input())
gcb_table = [[-1 for _ in range(k+1)] for _ in range(k+1)]

for i in range(1, k+1):
    for j in range(1, k+1):
        temp = gcb(i, j)
        gcb_table[i][j] = temp
        gcb_table[j][i] = temp
        
res = 0
l_k = range(1, k+1)
for part in itertools.product(l_k, l_k, l_k):
    gcb_first = gcb_table[part[0]][part[1]]
    res += gcb_table[gcb_first][part[2]]
print(res)

Submission status: Runtime Error

Solution code:
k=int(input())
d=0
for a in range(1,k+1) :
    for b in range(1,k+1):
        for c in range(1,k+1):
            d+=gcd(a,b,c)
print(d)

Submission status: Runtime Error

Solution code:
import numpy as np
k=int(input())
d=0
for a in range(1,k+1) :
    for b in range(1,k+1):
        for c in range(1,k+1):
            d+=gcd(a,b,c)
print(d)

Submission status: Runtime Error

Solution code:
import fractions

i=0
dammy=[0]*(K*K*K)
for a in range(1,K+1):
    for b in range(1,K+1):
        f=fractions.gcd(a,b)
        for c in range(1,K+1):


            ff = fractions.gcd(f,c)
            #dammy.append(ff)
            dammy[i]=ff
            i+=1

print(sum(dammy))

Submission status: Runtime Error

Solution code:
k = int(input())

count = [pow(k // max(i, 1), 3, mod) for i in range(k + 1)]

for i in range(k, 0, -1):
  for j in range(2 * i, k + 1, i):
    count[i] -= count[j]

sum_ = 0
for i in range(k + 1):
  sum_ += i * count[i]

print(sum_)

Submission status: Runtime Error

Solution code:
import math
K = int(input())
s = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    x = math.gcd(a,b)
    for c in range(1,K+1):
      s += gcd(x,c)
print(s)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
from itertools import product ##for i in z for j in z -> product(z,z)
k=int(input())
z=range(1,k+1)
print(sum(gcd(i,gcd(j,k)) product(z,z,z)))

Submission status: Runtime Error

Solution code:
k = int(input())
 
def gcd2(a,b):
    if b == 0:
        return a
    return gcd2(b,a%b)

def gcd3(a,b,c):
    return gcd2(gcd2(a,b), c)

ans = 0
for a in range(1,k+1):
    for b in range(i,k+1):
        for c in range(j, k+1):
            if a == b == c:
                ans += gcd3(a,b,c)
            elif a == b or b == c:
                ans += gcd3(a,b,c)*3
            else:
                ans += gcd3(a,b,c)*6

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
from itertools import product ##for i in z for j in z -> product(z,z)
k=int(input())
z=range(1,k+1)
print(sum(gcd(i,gcd(j,k)) product(z,z,z,z)))

Submission status: Runtime Error

Solution code:
from math import gcd
g=[201*[0]for _ in range(201)]
for i in range(1,201):
  for j in range(i,201):
    g[i][j]=gcd(i,j)
ans=0
for i in range(1,201):
  for j in range(1,201):
    for k in range(1,201):
    m=g[min(i,j)][max(i,j)]
    ans+=g[min(k,m)][max(k,m)]
print(ans)

Submission status: Runtime Error

Solution code:
import math
 
k=input()
 
ans=sum(sum(sum([[[math.gcd(a,math.gcd(b,c)) for c in range(1,k+1)] for b in range(1,k+1)] for a in range(1,k+1)],[]),[]))
print(ans)

Submission status: Runtime Error

Solution code:
import math

k=input()

ans=sum(sum(sum([[[math.gcd(a,b,c) for c in range(1,k+1)] for b in range(1,k+1)] for a in range(1,k+1)],[]),[]))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


def resolve():
	k = int(input())
	ans = 0
	for i in range(1, k+1):
		for j in range(1, k + 1):
			for k in range(1, k + 1):
				ans += reduce(math.gcd, [i, j, k])
	print(ans)

ressolve()

Submission status: Runtime Error

Solution code:
import fractions

def GCD(a,b,c):
    return fractions.gcd(math.gcd(a,b),c)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += GCD(i,j,k)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import itertools
from functools import reduce
N=int(input())
def A(i):
    def gcd(*numbers):
        return reduce(math.gcd, numbers)

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

    for i in itertools.product(GCD,repeat=3):
   
        GCD1.append(gcd(i[0],i[1],i[2]))
    
    return sum(GCD1) 
for i in range of (150,200)
print(A(N))

Submission status: Runtime Error

Solution code:
k=input()
 
def gcd(a,b,c):
  return max([i for i in range(1,min(a,b,c)+1) if (a%i==0)&(b%i==0)&(c%i==0)])
  
sum=0
 
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      sum+=gcd(a,b,c)

[[[sum+=gcd(a,b,c) for c in range(1+k)] for b in range(1+k)] for a in range(1,k+1)]

print(sum)

Submission status: Runtime Error

Solution code:
from fractions import gcd

k = int(input())
cnt = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            d = math.gcd(a+1,b+1)
            cnt = cnt + math.gcd(d,c+1)
print(cnt)

Submission status: Runtime Error

Solution code:
k=input()

def gcd(a,b,c):
  return max([i for i in range(1,min(a,b,c)+1) if (a%i==0)&(b%i==0)&(c%i==0)])
  
sum=0

for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      sum+=gcd(a,b,c)

print(sum)

Submission status: Runtime Error

Solution code:
K = int(input())
ans = 0

for i in range(K):
    i = i + 1
    for k in range(K):
        k = k + 1
        for j in range(K):
            j = j + 1
            
            ans += gcd(gcd(i, k),j)
            j = j + 1
        k = k + 1
    i = i + 1
            
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce


k = int(input())

def gcd(*numbers):
    return reduce(gcd, numbers)

k += 1
ans = 0

#for i in range(1,k):
#    for j in range(i,k):
#        #print(i,j)
#        if i == j:
#            ans += gcd(i,j)
#        else:
#            ans += gcd(i,j)*6

for i in range(1,k):
    for j in range(1,k):
        for h in range(1,k):
            #print(i,j,h)
            ans += gcd(i,j,h)


print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())
 
def gcd2(a,b):
    return gcd2(b,a%b)

def gcd3(a,b,c):
    return gcd2(gcd2(a,b), c)

ans = 0
for i in range(1,k+1):
    for j in range(i,k+1):
        for m in range(j, k+1):
            if i == j == m:
                ans += gcd3(i,j,m)
            elif i == j or j == m:
                ans += gcd3(i,j,m)*3
            else:
                ans += gcd3(i,j,m)*6

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
sum = 0
for i in range(1, N+1):
    for j in range(1, N+1):
		tmp=gcd(j,k)
        for k in range(1, N+1):
            sum += gcd(i, tmp)
print(sum)

Submission status: Runtime Error

Solution code:
import math
import numpy
K = int(input())

total = 0
tmp =0
 for a in range(1,K+1) :
     for b in range(1,K+1) :
        tmp=math.gcd(a,b)
         for c in range(1,K+1) :
             total += math.gcd(tmp,c)

print(total)

Submission status: Runtime Error

Solution code:
from math import gcd 
N = int(input())
i = 0
 
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            i += gcd(a, b, c)
            
print(i)

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
sum = 0
for i in range(1, N+1):
    for j in range(1, N+1):
		tmp=gcd(j,k);
        for k in range(1, N+1):
            sum += gcd(i, tmp)
print(sum)

Submission status: Runtime Error

Solution code:
import math

K = int(input())
ans = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += gcd(gcd(i, j), k)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

K = int(input())
ans=0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      ans += np.gcd.reduce([a,b,c])
print(ans)

Submission status: Runtime Error

Solution code:
from fraction import gcd
def main(): #startline-------------------------------------------
    k = int(input())
    ans = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                ans += gcd(gcd(i,j),l)

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Runtime Error

Solution code:
from fractions import gcd
N = int(input())
ans = 0
for i in range(N+1):
  for k in range(N+1):
    for l in range(N+1):
      ans += gcd(gcd(i,j),k)

print(ans)

Submission status: Runtime Error

Solution code:
def main(): #startline-------------------------------------------
    k = int(input())
    ans = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                ans += gcd(gcd(i,j),l)

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Runtime Error

Solution code:
import gcd from math
def main(): #startline-------------------------------------------
    k = int(input())
    ans = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                ans += gcd(gcd(i,j),l)

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Runtime Error

Solution code:
import math as np
K=int(input())
s=0
d=0
for a in range(1,K+1):
    if a%2==0:
        for b in range(2,K+1,2):
            if a>b:
                if a%b==0:
                    d=b
                else:
                    d=np.gcd(a%b,b)
            if a<b:
                if b%a==0:
                    d=a
                else:
                    d=np.gcd(b%a,a)
            if a==b:
                d=a
            for c in range(2,K+1,2):
                if c>d:
                    if c%d==0:
                        s+=d
                    else:
                        s+=np.gcd(c%d,d)
                if c<d:
                    if d%c==0:
                        s+=c
                    else:
                        s+=np.gcd(d%c,c)
                if c==d:
                    s+=c
    if a%2==1:
        for b in range(1,K+1,2):
            if a>b:
                if a%b==0:
                    d=b
                else:
                    d=np.gcd(a%b,b)
            if a<b:
                if b%a==0:
                    d=a
                else:
                    d=np.gcd(b%a,a)
            if a==b:
                d=a
            for c in range(1,K+1,2):
                if c>d:
                    if c%d==0:
                        s+=d
                    else:
                        s+=np.gcd(c%d,d)
                if c<d:
                    if d%c==0:
                        s+=c
                    else:
                        s+=np.gcd(d%c,c)
                if c==d:
                    s+=c
    if K%2==0:
        s+=K**3-(K//2)**3-(k//2+1)**3
    else:
        s+=K**3-(K//2)**3-(k//2)**3
print(s)

Submission status: Runtime Error

Solution code:
mport math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, k + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
print(ans)

Submission status: Runtime Error

Solution code:
import math

K = int(input(K))

ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      tmp = math.gcd(a,b)
      ans += math.gcd(tmp, c)

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
ans = 0
K = int(input())
 
for i in range(1, K+1):
	for j in range(1,K+1):
  		for k in range(1,K+1):
    		ans = ans + gcd(gcd(i,j), k)
      
print(ans)

Submission status: Runtime Error

Solution code:
import math

K = int(input(K))

ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      tmp = gcd(a,b)
      ans += gcd(tmp, c)

print(ans)

Submission status: Runtime Error

Solution code:
import math
def multi_gcd(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = fractions.gcd(ans, a[i])
    #print(ans)
    return ans
K = int(input())
sum_ = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            sum_ += multi_gcd([i, j, k])
print(sum_)

Submission status: Runtime Error

Solution code:
import math

K=int(input())
S=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      S+=gcd(gcd(i,j),k)

print(S)

Submission status: Runtime Error

Solution code:
import math
ans = 0
K = int(input())
 
for i in range(1, K+1):
	for j in range(1,K+1):
  		for k in range(1,K+1):
          ans = ans + math.gcd(math.gcd(i,j), k)
      
print(ans)

Submission status: Runtime Error

Solution code:
import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, j + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, l + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
K=int(input())+1
sum=0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            gcd1 = int(gcd(a,b))
            gcd2 = int(gcd(b,c))
            gcd = int(gcd(gcd1,gcd2))

            sum = sum+gcd
print(sum)

Submission status: Runtime Error

Solution code:
import math
ans = 0
K = int(input())
 
for i in range(1, K+1):
	for j in range(1,K+1):
  		for k in range(1,K+1):
    		ans = ans + math.gcd(math.gcd(i,j), k)
      
print(ans)

Submission status: Runtime Error

Solution code:
import math
 
ans = 0
K = int(input())
 
for i in range(1, K+1):
	for j in range(1,K+1):
  		for k in range(1,K+1):
    		ans += math.gcd(math.gcd(i,j), k)
      
print(ans)

Submission status: Runtime Error

Solution code:
import math
 
K = int(input())
 
for i in range(1, K+1):
	for j in range(1,K+1):
  		for k in range(1,K+1):
    		ans += math.gcd(math.gcd(i,j), k)
      
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for g in range(1,k+1):
      ans += math.gcd(math.gcd(i,j), g)

print(ans)

Submission status: Runtime Error

Solution code:
import math
 
K = input()
 
for i in range(1, K+1):
	for j in range(1,K+1):
  		for k in range(1,K+1):
    		ans += math.gcd(math.gcd(i,j), k)
      
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ans += math.gcd(math.gcd(i,j), k)
      
print(ans)

Submission status: Runtime Error

Solution code:
import math
k = int(input())
ans = 0

for i in range(1,k+1):
	for j in range(1,k+1):
      	for n in range(1,k+1):
          	ans += math.gcd(i,math.gcd(j,n))
print(ans)

Submission status: Runtime Error

Solution code:
import math
k = int(input())
ans = 0

for i in range(1,k+1):
	for j in range(1,k+1):
      	for k in range(1,k+1):
          	ans += math.gcd(i,math.gcd(j,k))
print(ans)

Submission status: Runtime Error

Solution code:
import math
k = int(input())
ans = 0

for i in range(1,k+1):
	for j in range(i+1,k+1):
      	for k in range(j+1,k+1):
          	ans += math.gcd(i,math.gcd(j,k))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    r = reduce(math.gcd, numbers)
    return r

def main():
    K = int(input())
    g = 0
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
            for k in range(1, K+1, 1):
            g += gcd(i, j, k)         
    print(g)
main()

Submission status: Runtime Error

Solution code:
import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      ans += gcd(a, b, c)

print(ans)

Submission status: Runtime Error

Solution code:

from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

n = int(input())
cnt=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):

            cnt += gcd(i,j,k)

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
cnt=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):

            cnt += gcd(i,j,k)

print(cnt)

Submission status: Runtime Error

Solution code:
from math import gcd
key = int(input())
sin = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        tmp = gcd(i,j)
        for m in range(1,k+1):
            sin += gcd(m,tmp)
print(sin)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
import sys

K = int(input())

def gcd(*args):
  return reduce(math.gcd, args)

if K==1:
  print("1")
elif K==2:
  print("9")
  sys.exit()

ans = math.sum(K)
for i in range(1,K):
  for j in range(i+1,K+1):
    ans += 6*math.gcd(i,j)
  
for i in range(1,K-1):
  for j in range(i+1, K):
    for k in range(j+1, K+1):
      ans += 6 * gcd(i,j,k)
      
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
N = N+1
sum = 0

import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(1, N):
    for j in range(1, N):
        for k in range(1, N):
            sum += gcd(gcd(i, j), k)

print( sum )

Submission status: Runtime Error

Solution code:
N = int(input())
N = N+1
sum = 0

import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(1, N):
    for j in range(1, N):
        for k in range(1, N):
            sum += (gcd(gcd(i, j), k)

print( sum )

Submission status: Runtime Error

Solution code:
n = int(input())
import math
ans = 0
n = int(input())
for i in range(1,n+1):
    for j in range(1,n+1):
        t = math.gcd(i,j)
        for k in range(1,n+1):
            ans += math.gcd(t,k)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
import math
ans = 0
t=0
n = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        t = math.gcd(i,j)
        for k in range(1,k+1):
            ans += math.gcd(t,k)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
import math
ans = 0
n = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        t = math.gcd(i,j)
        for k in range(1,k+1):
            ans += math.gcd(t,k)
print(ans)

Submission status: Runtime Error

Solution code:
k=int(input())
import math
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
          	a=math.gcd(i,j)
            ans+=math.gcd(a,l)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      total += gcd(i,j,k)
print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()

counta = 0
i = 0

while i < N - 2:
    j = i + 1
    while j < N - 1:
        if S[j] != S[i]:
            k = j + 1
            rest = [l for l in ['R', 'G', 'B'] if l != S[i] and l != S[j]]
            while k < N:
                if S[k] == rest[0] and  k - j != j - i:
                    counta += 1
                k += 1
        j += 1
    i += 1

print(counta)

Submission status: Runtime Error

Solution code:
import math
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k+1)] for _ in range(k+1)]
    for i ian range(1, k+1):
        for j in range(i, k+1):
            tmp = math.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
 
K=int(input())
 
S=0
for a in range(1,K+1):
    for b in range(1,K+1):
        calc=np.gcd(a,b)
        for c in range(1,K+1):
            if(c%calc==0):
                S+=calc
            else:
                S+=np.gcd(calc,c)
 
print(S)

Submission status: Runtime Error

Solution code:
from math import gcd
k=map(int,input())
r=range(1,k+1)
ans=0
for i in r:
  for j in r:
    for k in r:
      ans+=gcd(k,gcd(i,j))
print(ans)
# 間に合うはずなくない？？

Submission status: Runtime Error

Solution code:
import math
ans = 0
n = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += math.gcd(i,math.gcd(j,k))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
k=map(int,input())
r=range(1,k+1)
ans=0
for i in r:
  for j in r:
    for k in r:
      ans+=gcd(k,gcd(i,j))
print(ans)
# 間に合うはずなくない？？

Submission status: Runtime Error

Solution code:
from fractions import gcd

K = int(input())

res = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            tmp = [i,j,k]
            res += reduce(gcd,tmp)
print(res)

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(input())

import numpy as np

snp=np.array(S)
R=list(np.where(snp=='R')[0])
G=list(np.where(snp=='G')[0])
B=np.where(snp=='B')[0]
ans=0
for r in R:
    for g in G:
        d=abs(r-g)
        front=min(r,g)
        back=max(r,g)
        ans+=sum((B!=front-d)*(B!=back+d)*(B!=(front+back)/2))
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


K = int(input())

sum_gcd = 0
cand = itertools.combinations(K, 3))
for i in range(1, K + 1):
    for j in range(1, K + 1):
        g=gcd(i, j)
        for k in range(1, K + 1):
            sum_gcd += gcd(g, k)
print(sum_gcd)

Submission status: Runtime Error

Solution code:
import math
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k)] for _ in range(k)]
    for i ian range(1, k+1):
        for j in range(i, k+1):
            tmp = math.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
k=input()
s=0
for x in range(1,k+1):
  for y in range(1,k+1):
    for z in range(1,k+1):
      s+=math.gcd(x,gcd(y,z))
print(s)

Submission status: Runtime Error

Solution code:
from math import gcd
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k)] for _ in range(k)]
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            ans += gcd(i, j, k)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
 
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        tmp = math.gcd(a, b)
        for c in range(1, N + 1):
            ans += math.gcd(tmp, c)
 
print(ans)

Submission status: Runtime Error

Solution code:
import math

K = int(input())
ans = 0

for i in range(1,K+1):
  for j in range(1,K+1):
    ab = math.gcd(a, b)
    for k in range(1,K+1):
      ans += math.gcd(ab, c)

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

K = int(input())
sum = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(K):
    for j in range(K):
        tmp = math.gcd(i+1, j+1)
        for k in range(K):
            sum += gcd(g, k+1)
        
print(sum)

Submission status: Runtime Error

Solution code:
import math

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        x = math.gcd(i, j)
        for k in range(1, K+1):
            count += math.gcd(x, k)

print(ans)

Submission status: Runtime Error

Solution code:
ort math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
K = int(input())
B = list()
a = int()
b = int()
c = int()
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += np.gcd.reduce([a, b, c])
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())
s = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        for c in range(1, k+1):
            s += math.gcd(ab, c)
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np
k=int(input())
s=0
n=range(k+1)
for x,y,z in n:
	s+=np.gcd.reduce([x,y,z])
print(s)

Submission status: Runtime Error

Solution code:
    import sys, os, math
     
    def get_cd(n):
        cd = []
        for i in range(1, int(n/2)+1):
            if n % i == 0:
                cd.append(i)
            else:
                continue
        cd.append(n)
        return cd
     
    def get_gcd(a, b, c, cd_d):
        if 1 in [a, b, c]:
            return 1
        else:
            cd = sorted(list(set(cd_d[a]) & set(cd_d[b]) & set(cd_d[c])))
            return cd[-1]
     
    if __name__ == '__main__':
        k = int(input())
        cc_d = {}
        for i in range(1, k+1):
            cc_d[i] = get_cd(i)
     
        computed_d = {}
        s = 0
        for a in range(1, k+1):
            for b in range(a, k+1):
                for c in range(b, k+1):
                    if a == b == c:
                        s += a
                    else:
                        gcd = get_gcd(a, b, c, cc_d)
                        if a != b != c:
                            s += gcd*6
                        else:
                            s += gcd*3
        print(s)

Submission status: Runtime Error

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

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

def gcd_3(a,b,c):
    g = gcd(a,b)
    g = gcd(g,c)
    return g

sm = 0
for a in range(1, K+1):
    for b in range(a+1, K+1):
        for c in range(b+1, K+1):
            sm += gcd_3(a,b,c)

print(sm)