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:
import math
from functools import reduce
import itertools as itr

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

n = int(input()) 
aa = list(range(1, n+1 ))
bb = list(range(1, n+1))

cc = list(range(1, n+1))

def word_edit(word_list):
    new_words = []
    for word in word_list:
        new_word = word.lower()
        new_words.append(new_word)

    return new_words

sum1 = 0
for a in word_edit(aa):
    for b in word_edit(bb):
        for c in word_edit(cc):
            sum1+= gcd(a,b,c)
print(sum1)

Submission status: Runtime Error

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

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

line = int(input())

a = list(range(1,line + 1))
b = list(range(1,line + 1))
c = list(range(1,line + 1))

result = list(itertools.product(a,b,c))

all = 0

for i in result:
    tmp = gcd(i[0], i[1], i[2])
    all += tmp

print(all)

Submission status: Runtime Error

Solution code:
from functools import reduce
n = int(input())
x = range(1,n+1)
gcd = 0


for a in  x:
    for b in x:
        for c in x: 
            gcd += reduce(math.gcd, [a,b,c])
print(gcd)

Submission status: Runtime Error

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

print(z)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
x = range(1,n+1)
gcd = 0
from functools import reduce


for a in  x:
    for b in x:
        for c in x: 
            gcd += int(reduce(math.gcd, [a,b,c]))
print(gcd)

Submission status: Runtime Error

Solution code:
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
   r = a % b;
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(z,i3)
      s+=z2
print (s)

Submission status: Runtime Error

Solution code:
K=int(input())
import math
import itertools
count=0
for i in itertools.permutations(range(N)):
    g=list(i)
    count+=math.gcd(math.gcd(g[0],g[1]),g[2])
print(count)

Submission status: Runtime Error

Solution code:
import fractions as fr
k = int(input())
ans = (k+1)*k//2
tttt = [[0]*(k+1) for _ in range(k+1)]
for i in range(1, k+1):
  for j in range(1, k+1):
    if i == j:
      continue
    else:
      if tttt[i][j] != 0:
        g = tttt[i][j]
        ans += 3*g
      else:
        g = fr.gcd(i,j)
        tttt[i][j] = g
        tttt[j][i] = g
        ans += 3*g
for i in range(1, k-1):
  for j in range(i+1, k):
    for l in range(j+1, k+1):
      temp = tttt[i][j]
      temp2 = tttt[temp][l]
      ans+= 6*tee
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

def gcd(i):
    print(i)
    while i[1]:
        i[0], i[1] = i[1], i[0]%i[1]
    while i[2]:
        i[0], i[2] = i[2], i[0]%i[2]
    return i[0]

n = int(input())
if n == 1:
    print(1)
elif n==2:
    print(9)
else:
    l = [int(x) for x in range(1,n+1)]
    p = list(itertools.product(l,repeat=3))
    result = 0
    for i in p:
        result += gcd(list(i))
print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
K = int(input())
memo = np.zeros((K,K),int)
s = 0
for i in range(K):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if memo[i][j] != 0:
        if memo[memo[i][j]-1][k] != 0:
          s += memo[memo[i][j]-1][k]
        else:
          memo[memo[i][j]-1][k] = math.gcd(memo[i][j],k+1)
          memo[k][memo[i][j]-1] = memo[memo[i][j]-1][k]
          s += memo[k][memo[i][j]-1]
      else:
        
        memo[i][j] = math.gcd(i+1,j+1)
        memo[j][i] = memo[i][j]
        if memo[memo[i][j]-1][k] != 0:
          s += memo[memo[i][j]-1][k]
        else:
          memo[memo[i][j]-1][k] = math.gcd(memo[i][j],k+1)
          memo[k][memo[i][j]-1] = memo[memo[i][j]-1][k]
          s += memo[k][memo[i][j]-1]
print(s)

Submission status: Runtime Error

Solution code:

def q3():
import math
    k = int(input())
    sum_n = 0
    gcd_2_dict = {}
    def gcd(n1, n2):
        if n1 < n2:
            sorted_nums = tuple([n1, n2])
        else:
            sorted_nums = tuple([n2, n1])
        if sorted_nums in gcd_2_dict:
            return gcd_2_dict[sorted_nums]
        gcd_num = math.gcd(n1, n2)
        gcd_2_dict[sorted_nums] = gcd_num
        return gcd_num

    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sorted_nums = sorted([a, b, c])
                sum_n += gcd(gcd(sorted_nums[0], sorted_nums[1]), sorted_nums[2])

    print(sum_n)

q3()

Submission status: Runtime Error

Solution code:
N=int(input())
import math
import itertools
count=0
for i in itertools.permutations(range(N)):
    g=list(i)
    count+=math.gcd(math.gcd(g[0],g[1]),g[2])
print(count)

Submission status: Runtime Error

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

k=int(input())
l=[]
l.append([1, 1])
l.append([2 ,9])
l.append([3 ,30])
l.append([4 ,76])
l.append([5 ,141])
l.append([6 ,267])
l.append([7 ,400])
l.append([8 ,624])
l.append([9 ,885])
l.append([10, 1249])
l.append([11 ,1590])
l.append([12 ,2208])
l.append([13 ,2689])
l.append([14 ,3411])
l.append([15 ,4248])
l.append([16 ,5248])
l.append([17 ,6081])
l.append([18 ,7485])
l.append([19 ,8530])
l.append([20 ,10248])
l.append([21 ,11889])
l.append([22 ,13687])
l.append([23 ,15228])
l.append([24 ,17988])
l.append([25 ,20053])
l.append([26 ,22569])
l.append([27 ,25242])
l.append([28 ,28588])
l.append([29 ,31053])
l.append([30 ,35463])
l.append([31 ,38284])
l.append([32 ,42540])
l.append([33 ,46581])
l.append([34, 50893])
l.append([35 ,55362])
l.append([36 ,61824])
l.append([37 ,65857])
l.append([38 ,71247])
l.append([39 ,76884])
l.append([40 ,84388])
l.append([41 ,89349])
l.append([42 ,97881])
l.append([43 ,103342])
l.append([44 ,111528])
l.append([45 ,120141])
l.append([46 ,128047])
l.append([47 ,134580])
l.append([48 ,146316])
l.append([49 ,154177])
l.append([50 ,164817])
l.append([51 ,174438])
l.append([52 ,185836])
l.append([53 ,194157])
l.append([54 ,207927])
l.append([55 ,218812])
l.append([56 ,233268])
l.append([57 ,245277])
l.append([58 ,257857])
l.append([59 ,268182])
l.append([60 ,288216])
l.append([61 ,299257])
l.append([62 ,313635])
l.append([63 ,330204])
l.append([64 ,347836])
l.append([65 ,362973])
l.append([66 ,383709])
l.append([67 ,397042])
l.append([68 ,416448])
l.append([69 ,434025])
l.append([70 ,456967])
l.append([71 ,471948])
l.append([72 ,499740])
l.append([73 ,515581])
l.append([74 ,536073])
l.append([75 ,559758])
l.append([76 ,583960])
l.append([77 ,604833])
l.append([78 ,633651])
l.append([79 ,652216])
l.append([80 ,683712])
l.append([81 ,709065])
l.append([82 ,734233])
l.append([83 ,754734])
l.append([84 ,793188])
l.append([85 ,818917])
l.append([86 ,846603])
l.append([87 ,874512])
l.append([88 ,909496])
l.append([89 ,933081])
l.append([90 ,977145])
l.append([91 ,1006126])
l.append([92 ,1041504])
l.append([93 ,1073385])
l.append([94 ,1106467])
l.append([95 ,1138536])
l.append([96 ,1187112])
l.append([97 ,1215145])
l.append([98 ,1255101])
l.append([99 ,1295142])
l.append([100, 1342852])
l.append([101, 1373253])
l.append([102 ,1422195])
l.append([103 ,1453816])
l.append([104 ,1502376])
l.append([105 ,1553361])
l.append([106 ,1595437])
l.append([107 ,1629570])
l.append([108 ,1691292])
l.append([109 ,1726717])
l.append([110 ,1782111])
l.append([111 ,1827492])
l.append([112 ,1887772])
l.append([113 ,1925853])
l.append([114 ,1986837])
l.append([115 ,2033674])
l.append([116 ,2089776])
l.append([117 ,2145333])
l.append([118 ,2197483])
l.append([119 ,2246640])
l.append([120 ,2332104])
l.append([121 ,2379085])
l.append([122 ,2434833])
l.append([123 ,2490534])
l.append([124 ,2554600])
l.append([125 ,2609625])
l.append([126 ,2693919])
l.append([127 ,2742052])
l.append([128 ,2813988])
l.append([129 ,2875245])
l.append([130 ,2952085])
l.append([131 ,3003306])
l.append([132 ,3096024])
l.append([133 ,3157249])
l.append([134 ,3224511])
l.append([135 ,3306240])
l.append([136 ,3388576])
l.append([137 ,3444609])
l.append([138 ,3533637])
l.append([139 ,3591322])
l.append([140 ,3693924])
l.append([141 ,3767085])
l.append([142 ,3842623])
l.append([143,3912324])
l.append([144 ,4027884])
l.append([145 ,4102093])
l.append([146 ,4181949])
l.append([147 ,4270422])
l.append([148 ,4361548])
l.append([149 ,4427853])
l.append([150 ,4548003])
l.append([151 ,4616104])
l.append([152 ,4718640])
l.append([153 ,4812789])
l.append([154 ,4918561])
l.append([155 ,5003286])
l.append([156 ,5131848])
l.append([157 ,5205481])
l.append([158 ,5299011])
l.append([159 ,5392008])
l.append([160 ,5521384])
l.append([161 ,5610705])
l.append([162 ,5739009])
l.append([163 ,5818390])
l.append([164 ,5930196])
l.append([165 ,6052893])
l.append([166 ,6156139])
l.append([167 ,6239472])
l.append([168 ,6402720])
l.append([169 ,6493681])
l.append([170 ,6623853])
l.append([171 ,6741078])
l.append([172 ,6864016])
l.append([173 ,6953457])
l.append([174 ,7094451])
l.append([175 ,7215016])
l.append([176 ,7359936])
l.append([177 ,7475145])
l.append([178 ,7593865])
l.append([179 ,7689630])
l.append([180 ,7886244])
l.append([181 ,7984165])
l.append([182 ,8130747])
l.append([183 ,8253888])
l.append([184 ,8403448])
l.append([185 ,8523897])
l.append([186 ,8684853])
l.append([187 ,8802826])
l.append([188 ,8949612])
l.append([189 ,9105537])
l.append([190 ,9267595])
l.append([191 ,9376656])
l.append([192 ,9574704])
l.append([193 ,9686065])
l.append([194 ,9827097])
l.append([195 ,9997134])
l.append([196 ,10174780])
l.append([197 ,10290813])
l.append([198 ,10493367])
l.append([199 ,10611772])
l.append([200,10813692])
print(l[k][1])

Submission status: Runtime Error

Solution code:
K=int(sys.stdin.readline().rstrip())

def gcd(a,b):

    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

cnt1 = 0
cnt2 = 0
cnt3 = 0
for n1 in range(K):
    for n2 in range(K):
        temp = gcd(n1+1, n2+1)
        for n3 in range(K):
            cnt3 += gcd(temp, n3+1)
        

ans = cnt1 + cnt2 + cnt3
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())+1
out = 0
def gcd(x, y):
    for i in range(min(x, y), 1, -1):
        if x % i == 0 and y % i == 0:
            return i
for i in range(1,k):
    for i2 in range(1,k):
        for i3 in range(1,k):
            out += gcd(gcd(i,i2),i3)
print(out)

Submission status: Runtime Error

Solution code:
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
   r = a % b;
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b

l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(z,i3)
      s+=z2
print (s)

Submission status: Runtime Error

Solution code:
import math

K = int(sys.stdin.readline())
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

#acd_list = []
all_num = [i for i in range(1,k + 1)]
ans = 0 

#comb_list  = list(itertools.combinations(all_num, 3))
#print(comb_list)

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

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

result = []
for i in all_num:
  for j in all_num:
    for k in all_num:
      result.append([i, j, k])

for a,b,c in result:
#for a,b,c in comb_list:
    s = gcd(a, b,c)
    ans += s
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutations
a=int(input())
sum=0
b=[]
for i in range(1,a+1):
  b.append(int(i))
l=permutations(b)
for i in list(l):
  a=i[0]
  b=i[1]
  c=i[2]
  div=0
  for k in range(1,min(a,b,c)):
    if a%k==0 and b%k==0 and c%k==0:
      div=k
  sum+=div
print(sum,end="")

Submission status: Runtime Error

Solution code:
# coding: utf-8
 
N  = int(input())
sum_pre = 0
sum = 1
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
 
for x in range(N):  
    for i in range (N):
        for j in range(N):
            for k in range(N):
                sum_pre += gcd(*[i, j, k])
     sum += sum_pre
 
print(sum)

Submission status: Runtime Error

Solution code:
K=int(input())
import math
import itertools
count=0
for i in itertools.permutations(range(K)):
    g=list(i)
    count+=gcd(gcd(g[0],g[1]),g[2])
print(count)

Submission status: Runtime Error

Solution code:
import math
count=0
for p in range(1,k+1):
    for q in range(1,k+1):
        for r in range(1,k+1):
            count+=math.gcd(math.gcd(p,q), r)
            
print(count)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
k = int(input())
#3つとも違う数字
s3=0
for a in range(3,k+1):
    for b in range(2,k):
        for c in range(1,k-1):
            if c<b<a:
                s3+=gcd(gcd(b,c),a)
#2種類
s2 = 0
for a in range(2,k+1):
    for b in range(1,k):
        if b<a:
            s2+=gcd(a,b)
s = s3*6 + s2*6 +k*(k+1)/2
print(int(s)

Submission status: Runtime Error

Solution code:
k = int(input())

import math
ans = sum(list(range(k+1)))
ans1 = 0
ans2 = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans1 += math.gcd(i,j)

ans = ans + ans1*3

for i in range(1,K+1):
    for j in range(1,i):
        for l in range(1,l):
            ans2 += math.gcd(math.gcd(i,j),l)

ans += ans2*6
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
 
N  = int(input())
sum_pre = 0
sum = 1
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

for x in range(N):  
    for i in range (N):
        for j in range(N):
            for k in range(N):
                sum_pre += gcd([i, j, k])
     sum += sum_pre

print(sum)

Submission status: Runtime Error

Solution code:
import math
N = int(input())

out = 0
for a in range(1,N+1):
  for b in range(1,N+1):
    for c in range(1,N+1):
      temp = math.gcd(a, b)
      temp2 = math.gcd(temp2,c)
      out = out + temp1
print(out)

Submission status: Runtime Error

Solution code:
N=int(input())
import math
import itertools
count=0
for i in itertools.permutations(range(N)):
    g=list(i)
    count+=gcd(gcd(g[0],g[1]),g[2])
print(count)

Submission status: Runtime Error

Solution code:
import math
import itertools
import numpy as np
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
list2 = []
result = 0
n = int(input())
for i in range(1,n+1):
    if(not(is_prime(i))):
        for j in range(1,n+1):
          for k in range(1,n+1):
#            list2.append([i,j,k])
#            result +=  np.gcd.reduce((i,j,k))
#            print(result ,i,k,j)
    else:
        result += n*n-1
for i in range(1,n+1):
    if(is_prime(i)):
        result += i
print(result)
#print(list2)

Submission status: Runtime Error

Solution code:
K = int(input())

import math

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

Submission status: Runtime Error

Solution code:
import itertools
import math
k=int(input())
s=0
for a,b,c in itertools.combinations_with_replacement(range(1,n+1), 3):
    g=math.gcd(math.gcd(a,b),c)
    s+=g
print(s)

Submission status: Runtime Error

Solution code:
n = input()
total = 0

#a > b
def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

Submission status: Runtime Error

Solution code:
def resolve():
    K = int(input())
    temp = 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):
                Result = fractions.gcd(i, j)
                temp += fractions.gcd(Result, k)
    print(temp)
resolve()

Submission status: Runtime Error

Solution code:

N = int(input())
sum = 0
for a in range(1, N+1):
    if a == 1:
        sum += 1 * N**2
        continue

    for b in range(1, N+1):
        if b == 1:
            sum += 1 * N
            continue

        for c in range(1,N+1):
            if c == 1:
                sum += 1
                continue
            sum += math.gcd(math.gcd(a, b), c)

print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def gcd3(a, b, c):
    return gcd(gcd(a,b), c)

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

k = int(input())
sum = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            if a == 0 or b == 0 or c == 0:
                sum += 1
            else
                sum += gcd3(a+1,b+1,c+1)
print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


K = int(input())
sum = 0
ijkrange = np.arange(1, K+1)

for i in ijkrange:
    for j in ijkrange:
        for l in ijkrange:
            sum += gcd(i, gcd(j, l))

print(sum)

Submission status: Runtime Error

Solution code:
import math
k=input()
a=1
b=1
c=1
s=0
for p in range(k):
  b=1
  for q in range(k):
    c=1
    for i in range(k):
      g=math.gcd(a,b)
      g=math.gcd(g,c)
      s=s+g
      c=c+1
    b=b+1
  a=a+1
print(s)

Submission status: Runtime Error

Solution code:
import numpy as np

k = int(input())

answer = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            answer += np.gcd.reduce([a,b,c])

print(answer)

Submission status: Runtime Error

Solution code:
import sys
import math
k = int(sys.stdin.readline())
a = 1
t = 0
while a <= k:
  b = 1
  while b <= k:
    c = 1
    while c <= k:
      t += math.gcd(a,b,c)
      c += 1
    b += 1
  a += 1
print(t)

Submission status: Runtime Error

Solution code:
import math
N = int(input())

out = 0
for a in range(1,N+1):
  for b in range(1,N+1):
    for c in range(1,N+1):
      temp = math.gcd(a, b, c)
      out = out + temp
print(out)

Submission status: Runtime Error

Solution code:
from gcd import math
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):
                res=res+gcd(gcd(i,j),k)
print(res)

Submission status: Runtime Error

Solution code:
from collections import deque, Counter
from itertools import chain, combinations
import json
import numpy as np
import bisect
import sys
import math

sys.setrecursionlimit(10 ** 8)
# mem = {}

M = 10 ** 9 + 7

mem = {}


def gcd(a, b, c):
    if (a, b, c) not in mem:
        mem[(a, b, c)] = math.gcd(math.gcd(a, b), c)
    return mem[(a, b, c)]


def main():
    K = int(input())
    t1 = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            for c in range(b + 1, K + 1):
                t1 += gcd(a, b, c) * 6
    t2 = 0
    for ab in range(1, K + 1):
        for c in range(ab + 1, K + 1):
            t2 += math.gcd(ab, c) * 6
    t3 = 0
    for abc in range(1, K + 1):
        t3 += abc
    print(t1 + t2 + t3)


if __name__ == "__main__":
    main()

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(i,j,k)
      
print(ans)

Submission status: Runtime Error

Solution code:
@lru_cache(maxsize=10**5)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)

Submission status: Runtime Error

Solution code:
import collections

K = int(input())

a = []
for i in range(1,K+1):
    for j in range(1, K+1):
        a.append(gcd(i,j))
        
col = collections.Counter(a)

sum = 0
for k in range(1, K+1):
    for key, value in col.items():
         sum += gcd(k, key) * value
print(sum)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import itertools as itr

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

n = int(input()) 
aa = list(range(1,n ))
bb = list(range(1, n))
cc = list(range(1, n))

for a,b,c in itr.product(aa,bb,cc):
            sum1= sum1 + gcd(a,b,c)
            
print(sum1)

Submission status: Runtime Error

Solution code:
def gcd(x, y): 
   while y: 
       x, y = y, x % y 
   return x 
``
k = int(input())

result = 0
cache = {}
for x in range(1, k+1):
    for y in range(1, k+1):
        for z in range(1, k+1):
            tup = tuple(sorted((x, y, z)))
            if tup in cache:
                result += cache[tup]
            else:
                cache[tup] = gcd(x, gcd(y, z))
                result += cache[tup]
            result += gcd(x, gcd(y, z))
print(result)

Submission status: Runtime Error

Solution code:
import sys

n = int(sys.argv[1])
total = 0

def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

Submission status: Runtime Error

Solution code:
import math
import itertools

# a = 6
# b = 4
#
# print(math.gcd(a, b))
k = int(input())
kk = k + 1
ans = 0
for i in range(1, kk):
    # print(i)
    for ii in rangea(1, kk):
        # print(ii)
        for iii in range(1, kk):
            # print((i,ii,iii))
            gcd2 = math.gcd(ii, iii)
            gcd3 = math.gcd(i, gcd2)
            ans += gcd3

print(ans)

Submission status: Runtime Error

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

sum = 0
for i in range(1,ki+1):
    for j in range(1,ki+1):
        for k in range(1,ki+1):
            tk = gcd(i,j)
            tr = gcd(tk,k)
            sum +=tr

Submission status: Runtime Error

Solution code:
function GCM(x, y):
  if x == y:
    return x
  if x < y:
    s = x
    x = y
    y = s
  
  a = x%y
  if a == 0:
    return y
  return GCM(y, a)

k = int(input())
res = 0
same1 = 0
same2 = 0
rate = [6,3,1]
for p in range(1,k+1):
  for q in range(p, k+1):
    same1 = int(p==q)
    gcm = GCM(q,p)
    for r in range(q, k+1):
      same2 = int(q==r)
      gcm = GCM(r,gcm)
      res += gcm*rate[same1+same2]
print(res)

Submission status: Runtime Error

Solution code:
import sys
import fractions
from collections import Counter, defaultdict, deque
from functools import reduce

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    k = I()

    def gcd(number):
        return fractions.gcd(fractions.gcd, number)

    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)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
#import math
from fractions import gcd

##get int
first_input = list(map(lambda x:int(x), input().split(" ")))
#second_input = list(map(lambda x:int(x), input().split(" ")))

##get float
#first_input = list(map(lambda x:float(x), input().split(" ")))
#second_input = list(map(lambda x:float(x), input().split(" ")))

##get string
#first_input = input().split(" ")

K = first_input[0]

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

print(gcd_sum)

Submission status: Runtime Error

Solution code:
import itertools
import math
K=int(input())
A=[]
for i in range(1,K+1):
  A.append(i)

 
ans=0
for a,b,c in (itertools.product(A,A,A)):
    print(a,b,c)
    x=math.gcd(a,b)
    y=math.gcd(x,c)
    ans +=y
    
 
    
print(sum(ans))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
n,k = map(int, input().split())
s = 0
for i in range(k):
  for j in range(k):
    for h in range(k):
      s += gcd(i+1,j+1,h+1)
print(s)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

k = int(input())



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

answer = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            answer += np.gcd.reduce([a,b,c])

print(answer)

Submission status: Runtime Error

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')
 
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
K = iin()
 
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)
            tmp = math.gcd(tmp, c)
            ans += tmp
print(ans)
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')
 
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

K = iin()

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            if a == 1 or b == 1 or c == 1:
                ans += 1
            elif a == b == c:
                ans += a
            elif a == b:
                ans += math.gcd(a, c)
            elif a == c:
                ans += math.gcd(b,c)
            else:
                tmp = math.gcd(a, b)
                if tmp == 1:
                    ans += 1
                else:
                    tmp = math.gcd(tmp, c)
                    ans += tmp
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())

S =[]

a, b, c = 1, 1, 1

for i in range(K):
	for j in range(K):
      	for k in range(K):
          	n = gcd(a+i, b+j, c+k)
            S.append(n)

print(sum(S))

Submission status: Runtime Error

Solution code:
@lru_cache(maxsize=10**6)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)