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:
K=int(input())
ans=0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            n=math.gcd(a,b,c)
            ans=ans+n

print(ans)

Submission status: Runtime Error

Solution code:
import math
n=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+=math.gcd(i,math.gcd(j,l))

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
k=int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans=0
for i in range(1,k+1):
  for j in range(j,k+1):
    for l in range(l,k+1):
      if l==i:
        ans+=gcd(i,j,l)
      elif i==j or j==l:
        ans+=2*gcd(i,j,l)
      else:
        ans+=gcd(i,j,l)
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
 
N  = int(input())
sum = 0

import math
from functools import reduce

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

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

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

print(sum)

Submission status: Runtime Error

Solution code:

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = map(int, input().split())
# N=3
# M=1
# A=[5,4,2,1]

cnt = 0
cnt1 = 0

# for i in range(N):
#     cnt = cnt + A[i]
#
# for i in range(N):
#     if A[i] / cnt > 1 / 4 / M:
#         cnt1 = cnt1 + 1

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

# a1 = N % 10
# a2 = ((N-a1*10) % 100)/10
# a3 = ((N-a1*100-a2*10))/100

print(sum)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
k=int(input())
import fractions

for p in range(1,k+1):
    for q in range(1,k+1):
        for r in range(1,k+1):
            ans=p
            ans = fractions.gcd(ans, q)
            ans = fractions.gcd(ans, r)
            sum_g+=ans
            ans=0
print(sum_g)

Submission status: Runtime Error

Solution code:
goal = 0
n = int(input())
n+=1
for i in range(1,n):
    for j in range(1,n):
        for k in range(1,n):
            list1 = [i,j,k]
            ans = list1[0]
            for m in range(1, 3):
                ans = math.gcd(ans, list1[m])
            goal +=ans

print(goal)

Submission status: Runtime Error

Solution code:
from itertools import product
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        ans+=reduce(gcd,S)
    print(ans)


resolve()

Submission status: Runtime Error

Solution code:
import fractions
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
tmp_sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      tmp_list = [i,j,k]
      tmp_sum += gcd_list(tmp_list)
print(tmp_sum)

Submission status: Runtime Error

Solution code:
import fractions

K = input()

Sum = 0

for A in range(K):
    a = A + 1
    for B in range(K):
        b = B + 1
        for C in range(K):
            c = C + 1

            Sum = Sum + fractions.gcd(fractions.gcd(a, b), c)

print(Sum)

Submission status: Runtime Error

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

print(cnt)

Submission status: Runtime Error

Solution code:
k = int(input())
import math
k1 = 0
k2 = 0
k3 = 0
count = 0
for i in range(0,k):
  k1 = k1 + 1
  for j in range(0,i):
    k2 = k2 + 1
    for k in range(0, j):
      k3 = k3 + 1
      if k1==k2==k3:
        count = count + k1
      elif k1==k2 or k2==k3 or k3==k1:
        count = count + 3*math.gcd(k1,k2,k3)
      else:
        count = count + 6*math.gcd(k1,k2,k3)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
def gcd(a,b,c):
  return gcd(gcd(a,b),c)
ct=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):
      ct+=gcd(i,j,k)
print(ct)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
k = int(input())
sum = 0
for a in xrange(1,k+1):
    for b in xrange(1,k+1):
        for c in xrange(1,k+1):
            sum += gcd(a,b,c)
print(sum)

Submission status: Runtime Error

Solution code:
import math

n=int(input())

sum=0
for i in range(1,n):
  for j in range(1,n):
    for k in range(1,n):
      y=[[i,j,k]]
      for h in range(z):
        x=math.gcd(h[0],h[1],h[2])
        sum=sum+x
print(sum)

Submission status: Runtime Error

Solution code:
import math 
K=int(input())
A=[]
for i in range(K):
  for j in range(K):
    for k in range(K):
      s=gcd(i,j,k)
      A.append(s)
print(sum(A)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  while b!=0:
    a,b=b,a%b
  return a
def gcd(a,b,c):
  return gcd(gcd(a,b),c)
ct=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):
      ct+=gcd(a,b,c)
print(ct)

Submission status: Runtime Error

Solution code:
from functools import reduce
k=int(input())
m=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for p in range(1,k+1):
            l=[i,j,p]
            m+=reduce(fractions.gcd,l)
print(m)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd

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 += gcd(i,j,k)
      
print(sum)

Submission status: Runtime Error

Solution code:
def main():
    from collections import deque
    from functools import reduce
    from math import gcd

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

    K = int(input())
    ans = 0

    for _ in range(1, K + 1):
        for _ in range(1, K + 1):
            for _ in range(1, K + 1):
                ans += gcd3(_, b, c)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import fractinons
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+=fractions.gcd(fractions.gcd(a,b),c)
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

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

sum = 0
K = int(input())

for i in range(K):
  for j in range(K):
    for k in rage(K):
      sum += gcd(i,j,k)
      
print(sum)

Submission status: Runtime Error

Solution code:
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):
            tmp = math.gcd(i, j)s
            res += math.gcd(tmp, k)

print(res)

Submission status: Runtime Error

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

n= 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:
k=int(input())+1
l=[]
for a in range(1,k):
    for b in range(1,k):
        for c in range(1,k):
            l.append(math.gcd(a,math.gcd(b,c)))
print (sum(l))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=int(input())
b=0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      x=min(i,j,k)
      List=[]
      for l in range(1,x+1):
        if i%l==0 and j%l==0 and i%k==0 :
          List.append(l)
      b+=max(List)
print(b)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
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:
def main():
    k = int(input())
    gcds = list(sorted([gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)]))
    j = 0
    s = list(set(gcds))
    m = k**2-1
    gcdss = [0]*len(s)
    for i, l in enumerate(s):
        while gcds[j] == l:
            j += 1
            gcdss[i] += 1
        if j == m:
            break
    ans = sum([gcd(i, j)*n for i in range(1, k+1) for j, n in zip(s, gcdss)])
    print(ans)
            
    
def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

for p in range(1,k+1):
    for q in range(1,k+1):
        for r in range(1,k+1):
            ans=p
            ans = math.gcd(ans, q)
            ans = math.gcd(ans, r)
            sum_g+=ans
            ans=0
print(sum_g)

Submission status: Runtime Error

Solution code:
N = int(input())
sum=0
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
from itertools import product
pools = product(N,N,N)
for i, j ,k in pools:
  sum =sum + gcd(i, j, k)

Submission status: Runtime Error

Solution code:
K = int(input())

import gcd from math

def g(a,b,c):
  retunr gcd(gcd(a,b),c)

a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      a += g(i,j,k)

print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
class GCD:

    def culc(self, K):
        ret = 0
        self.numlist = dict()
        for i in range(1,K+1):
            for j in range(1, K+1):
                for k in range(1,K+1):
                    ret += self.gcd(i,j,k)
        return ret

    def gcd(self, a,b,c):
        l = [a,b,c]
        l.sort()
        l = tuple(l)
        if l in self.numlist:
            return self.numlist[l]
        else:
            temp_ = self.gcd_(l[0],l[1])
            temp_ = self.gcd_(temp_, l[2])
            self.numlist[l] = temp_
            return temp_

    def gcd_(self,a,b):
        mod = max(a,b) % min(a,b)
        if mod == 0:
            ret = min(a,b)
            return ret
        else:
            self.gcd_(min(a,b), mod)

K = int(input())
gcd = GCD()
ret = gcd.culc(K)
print(ret)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

k = int(input())
tmp = 0
for a range(1, k+1):
  for b range(1, k+1):
    for c range(1, k+1):
      tmp += gcd_list([a, b, c])
print(tmp)

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import math
from functools import reduce

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

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

# def gcd(nums):
#     return functools.reduce(euclid, nums)


K = int(input())

hoge = []
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            hoge.append(gcd(i, j, k))

print(sum(hoge))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

K = int(input())
ans =  0
for x,y,z in range(K):
  ans += int(gcd(x,y,z))
print(ans)

Submission status: Runtime Error

Solution code:
import math

ans = 0
ans += 0.5*k*(k+1)
# print(ans)

for a in range(1, k):
    for b in range(a+1,k+1):
        n = math.gcd(a, b)
        ans += n*6
        # print(a, b, n)

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

        #
        #
        # for c in range(b+1, k+1):
        #     ans += math.gcd(n, c)*3
        # print(a, b, c)

print(int(ans))

Submission status: Runtime Error

Solution code:
a=int(input())
s =0
for i in range(a):
    for j in range(a):
        for k in range(a):
            for n in range(min(i,j,k)+1):
                if a%(n+1) == 0 and b%(n+1) == 0 and c%(n+1) ==0:
                    gcd = n+1
            s = s + gcd
print(s)

Submission status: Runtime Error

Solution code:
import fractions

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

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

num = int(input())
list = []
for i in range(1,num):
  for j in range(i,num):
    for k in range(j,num):
      list.add(gcd(i,j,k))
print(sum(list))

Submission status: Runtime Error

Solution code:
import functools
n = int(input())

def gcd(nums):
    return functools.reduce(euclid, nums)

a = 0

for i in range(n):
  for j in range(n):
    for k in range(n):
      num = [i+1, j+1, k+1]
      a = a + gcd(num)
      
print(a)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

for i in range(1, K):
    for j in range(i+1, K+1):
#         print(3, (i,j,j))
        ans += 3 * np.gcd.reduce([i,j,j])
for i in range(1, K+1):
    for j in range(1, i):
#         print(3, (i,j,j))
        ans += 3 * np.gcd.reduce([i,j,j])
        
for i in range(1, K-1):
    for j in range(i+1, K):
        for k in range(j+1, K+1):
#             print(6, (i,j,k))
            ans += 6 * np.gcd.reduce([i,j,k])
print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
ans = (1+N)*N/2
for i in range(1,N+1):
  for j in range(1,i):
    ans += math.gcd(i,j)*3
for i in range(!,N+1):
  for j in range(1,i):
    if i== j:
      break
    for k in range(1,j):
      if i == k or j == k:
        break
      else:
        ans += math.gcd(i,j,k)*6
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

import math

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 += gcd(a,b,c)

print(answer)

Submission status: Runtime Error

Solution code:
K = int(input())

if K == 1:
  print(1)
  
def f(K):
  s =  0
  count = 0
  for i in range(2,K+1):
    if K % i != 1:
      s += i
      count += 1
  return 3*K + s - count  
  
else:
  ans = 0
  for i in range(2,K+1):
    ans += f(K)
  print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd
import numpy as np
k = int(input())
point = 0
li = [[0 for i in range(k+1)]for j in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        li[i][j] = gcd(i,j)
lin = []
for i in li:
    for j in i:
        if j != 0:
            lin.append(j)
for i in lin:
    for j in range(1,k+1):
        point += li[i][j]
print(point)

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np

def gcd(num_list):
    tmp = np.gcd(num_list[0], num_list[1])
    return np.gcd(tmp, num_list[2])

def A():
    n = stdin.readline().rstrip()
    flag = bool()

    for st in n:
        if st == '7':
            flag = True

    if flag:
        print("Yes")
    else:
        print("No")  


def B():
    n = stdin.readline().rstrip()
    sum = 0

    for i in range(1, int(n) + 1):
        if not(i % 3 == 0 or i % 5 == 0):
            sum = sum + i

    print(sum)

def C():
    n = stdin.readline().rstrip()
    sum = 0
    lis = list()

    lis = [[a, b, c] for a in range(1, int(n) + 1) for b in range(1, int(n) + 1) for c in range(1, int(n) + 1)]

    for i in lis:
        sum = sum + gcd(i)

    print(sum)


if __name__ == "__main__":
    C()

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
k = int(input())

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(gcd(a,b), c)

print(sum)

Submission status: Runtime Error

Solution code:
n=int(input())
a=0
for i in range(n+1):
    for j in range(n+1):
        for k in range(n+1):
            a+=g[g[i][j]][k]
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[i][j]][k]
print(S)

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
k=int(input())
re=0
for a in range (1,k+1):
 for b in range (1,k+1):
  for c in range (1,k+1):
   re=math.gcd(a,b,c)+re
print(re)

Submission status: Runtime Error

Solution code:
import numpy as np

k = int(input())

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

print(cnt)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
memo = {}
ans = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    for c in range(1, n+1):
      elem = [a, b, c]
      elem.sort()
      if (a, b, c) not in memo:
        gcd_ans = math.gcd(a, b, c)
        memo[(a, b, c)] = gcd_ans
      else:
        gcd_ans = memo[(a, b, c)]
      ans += gcd_ans
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 l in range(1,k+1):
            m = math.gcd(i,j)
            ans += math.gcd(m,l)

print(ans)

Submission status: Runtime Error

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

import math

k = int(input())

sum = 0
for p in range(k):
    for q in range(k):
        for r in range(k):
            sum += math.gcd(p + 1, q + 1, r + 1)
print(sum)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

#from fractions import gcd

sys.setrecursionlimit(10 ** 9)

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

K = int(input())

ans = 0
M = np.zeros(K+1, dtype=int)
for i in range(1,K+1):
    for j in range(1,K+1):
        M[j] =  gcd(i,j)
        
        for k in range(1,K+1):
            ans += gcd(M[j],k)
            ans += gcd(gcd(i,j),k)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
N=list(range(1,n+1))
print(sum([gcd2(a,b,c) for a,b,c in [[a, b, c] for a in N for b in N for c in N]]))

Submission status: Runtime Error

Solution code:
N = int(input())

h = itertools.combinations_with_replacement(list(range(1,N+1)), 3)

import math
from functools import reduce

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

ans = 0
for n1, n2, n3 in h:
  if n1 == n2 == n3:
    ans += gcd(n1,n2,n3)
  else:
    ans += gcd(n1,n2,n3)*3
print(ans)

Submission status: Runtime Error

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


K = int(input())

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
import fractions
K = int(input())
out = 0
L = [0]*K
gcd = [[0]*K for i in range(K)]
for i in range(1,201):
    for j in range(1,201):
        A = fractions.gcd(i,j)
        gcd[i-1][j-1] = A
        L[A-1]+=1


for i in range(1,201):
    for j in range(1,201):
        out+=gcd[i-1][j-1]*L[j-1]

print(out)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import itertools


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


x = input()
_sum = [gcd(*i) for i in itertools.product(range(x), repeat=3)]
print(sum(_sum))

Submission status: Runtime Error

Solution code:
import itertools
import math

m = int(input())
g = range(1, m+1)
res = 0
for c in itertools.combinations(g, 3):
  set_c = set(c)
  if len(set_c) == 3:
    n = 6
  elif len(set_c) == 2:
    n = 3
  else:
    n = 1
  tmp_res = math.gcd(c[0], c[1], c[2])
  res += tmp_res * n
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


k=input()
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    d=gcd(i,j)
    for l in range(1,k+1):
      if d!=1:
        ans+=gcd(d,l)
      else:
        ans+=1


print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
total = 0
for a in range(K):
  for b in range(K):
    for c in range(K):
      total += math.gcd(a, b)
print(total)

Submission status: Runtime Error

Solution code:
from math import gcd

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a,b)
        if g == 1:
            ans += K
        else:
            for c in range(1,K+1):
                ans += gcd(g,c)
                cnt += 1
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
n=int(input())
ans=0
for i in range(n):
  for k in range(i,n):
    for _ in range(k,n):
      if i==_:
        ans+=gcd(i,k,_)
      else if i==k or k==_:
        ans+=gcd(i,k,_)*3
      else:
        ans+=gcd(i,k,_)*6
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
K = int(input())
A = [i for i in range(1, K)]
B = [i for i in range(1, K)]
C = [i for i in range(1, K)]

cnt = 0
for a in A:
  for b in B:
    for c in C:
      N = [a,b,c]
      ans = N[0]
      for i in range(1, 3):
        ans = fractions.gcd(ans, a[i])
      cnt += ans
print(cnt)

Submission status: Runtime Error

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

# def gcd2(a,b,c):
# 	a=gcd(a,b)
# 	a=gcd(a,c)
# 	return a

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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
ans = 0
K = [0 for _ in range(200)]
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    K[math.gcd(i,i2)] += 1
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    ans += K[i] * math.gcd(i,i2)
print(ans)

Submission status: Runtime Error

Solution code:
import math
ans = 0
N = int(input())
for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += 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 k in range(1,k+1):
      ans += math.gcd(i,j,k)
print(ans)

Submission status: Runtime Error

Solution code:
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):
            if j < k:
                j,k = k,j
            temp = gcd(j,k)
            if i < temp:
                i,temp = temp,i
            ans += gcd(i,temp)
print(ans)

Submission status: Runtime Error

Solution code:
import math
K = int(input())
ans = 0
for a in range(1, K+1):
  for b in range(1, a+1):
    for c in range(1, b+1):
      if a != b and b != c and c != a:
        ans += math.gcd(a,b,c) * 6
      elif a == b and b == c:
        ans += math.gcd(a,b,c)
      else:
        ans += math.gcd(a,b,c) * 3
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input(k))
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            d = max([i, j, k])
            if i % d == 0 and j % d == 0 and k % d == 0:
                ans += d
            else:
                d -= 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
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 += math.gcd(a,b,c)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from functools import reduce
from itertools import product

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

def gcd_list(A): return reduce(gcd, A)

K = int(input())
S = K * (K + 1) // 2
for a, b in combinations(range(1, K+1), 2):
    S += 6 * gcd(a, b)
for a, b, c in combinations(range(1, K+1), 3):
    S += 6 * gcd_list((a, b, c))
print(S)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

n= 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:
def main():
    k = int(input())
    r = 0
    for ia in range(1, k + 1):
        for ib in range(1, k + 1):
            for ic in range(1, k + 1):
                t1 = gcd(ib, ic)
                r += gcd(t1,ia)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
k = int(input())
li = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      n = (a,b,c)
      li.append(reduce(gcd,n))

print(sum(li))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

K = int(input())

dp = [[0] * 201 for _ in range(201)]
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            if dp[a][b] == 0:
                dp[a][b] = math.gcd(a, b)
            if dp[dp[a][b]][c] == 0:
                dp[dp[a][b]][c] = math.gcd(dp[a][b], c)
            ans += dp[dp[a][b]][c]

print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

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

Submission status: Runtime Error

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

n = int(raw_input())
sm = 0;
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      sm += gcd(gcd(i,j),k)
      
print(sm)

Submission status: Runtime Error

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


count = 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)
            count += math.gcd(a,l)
print(count)

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 k in range(1,K+1):
      ans+=math.gcd(i,j,k)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

k = input()
sum = 0
for p in range(k):
    for q in range(k):
        for r in range(k):
            sum += np.gcd.reduce([i,j,k])

print(sum)

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import math

n = int(input())

sum_ = 0
for a in range(1, n+1):
  for b in range(1, n+1):
    for c in range(1, n+1):
      sum_ += math.gcd(a, b, c)
    
print(sum_)

Submission status: Runtime Error

Solution code:
import math

num = int(input())
ans = 0
for a in num:
    for b in num:
        for c in num:
            ans += math.gcd(a, b, c)
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
	while(y):
		x,y = y,x%y
	return x
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,gcd(b,c))

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
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:
import math


def gcd(a, b, c):
  d = math.gcd(a, b)
  return math.gcd(c, d)

K = int(input())
sum = 0

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

Submission status: Runtime Error

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