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: Accepted

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):
        for k in range(1, n + 1):
            sum += gcd(gcd(i, j), k)
print(sum)

Submission status: Accepted

Solution code:
import math
from functools import reduce
from itertools import product
 
x = int(input())
print(sum(map(lambda x: reduce(math.gcd, x), product(range(1, x+1), repeat=3))))

Submission status: Accepted

Solution code:
import math
from itertools import product
 
x = int(input())

s = 0
for a, b, c in product(range(1, x+1), repeat=3):
  s += math.gcd(math.gcd(a, b), c)
print(s)

Submission status: Accepted

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)
        for c in range(1,K+1):
            ans += gcd(g,c)
print(ans)

Submission status: Accepted

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):
    GCD = gcd(i, j)
    for l in range(1, k+1):
      ans += gcd(GCD, l)
print(ans)

Submission status: Accepted

Solution code:
n=3
k=int(input())
INF=10**9+7
l=[0]*k
ans=0
for i in range(k-1,-1,-1):
    x=i+1
    temp=pow(k//x,n,INF)
    for j in range(2,k//x+1):
        temp=(temp-l[j*x-1])%INF
    l[i]=temp
    ans=(ans+x*temp)%INF
print(ans)

Submission status: Accepted

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)
        for c in range(1, K+1):
            ans += gcd(g, c)

print(ans)

Submission status: Accepted

Solution code:
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    N = iRaw()
    ans = 0
    for a in range(1,N+1):
        for b in range(1,N+1):
            for c in range(1,N+1):
                ans+=math.gcd(a,math.gcd(b,c))
    return ans

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import math
  
def main():
  k=int(input())
  cur=0
  for a in range(1,k+1):
    for b in range(1,k+1):
      for c in range(1,k+1):
        cur+=math.gcd(math.gcd(a,b),c)
        
  return cur
print(main())

Submission status: Accepted

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    k = I()
    from math import gcd
    s=0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for e in range(1,k+1):
                s+=gcd(gcd(i,j),e)
    print(s)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math

from collections import deque 
from functools import reduce
from functools import lru_cache

@lru_cache(maxsize=None)
def gc(a, b):
    if (a % b == 0):
        return b
    return(gc(b, a%b))
# input = sys.stdin.readline

n = int(input())

sum = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        g = gc(i, j)
        for k in range(1, n+1):
            sum += gc(g, k)
print(sum)

Submission status: Accepted

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


N = int(input())
add = 0
for i in range(1,N+1):
	for j in range(1,N+1):
		for k in range(1,N+1):
			temp = gcd(i,j)
			add += gcd(temp,k)
print(add)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math

from collections import deque 
from functools import reduce
from functools import lru_cache

# input = sys.stdin.readline

n = int(input())

gcd_num = 0

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

Submission status: Accepted

Solution code:
# import numpy as np

# aとbの最大公約数
def GCD(a,b):
    # ユークリッドの互除法
    if b == 0:
        return a
    else:
        return GCD(b,a % b)



k = int(input())
sum = 0
count = [0] * k

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

# print(count)
for i in range(1, k + 1):
    for j, n in enumerate(count):
        sum = sum + GCD(i, j + 1) * n
print(sum)

Submission status: Accepted

Solution code:
GCD = [[-1] * 210 for _ in range(210)]


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if GCD[a][b] == -1:
        if b == 0:
            return a
        GCD[a][b] = gcd(b, a % b)
    return GCD[a][b]


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k):
        for j in range(i+1, k+1):
            sum += gcd(i, j)*6

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k-1):
        for j in range(i+1, k):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n=int(input())
s=0
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,math.gcd(j,k))
print(s)

Submission status: Accepted

Solution code:
import fractions as ma
import collections
n=int(input())
total=0

d=collections.defaultdict(int)

for a in range(1,n+1):
  for b in range(1,n+1):
    d[ma.gcd(a,b)]+=1
    
for a in range(1,n+1):
  for key in d.keys():
    total += ma.gcd(key,a)*d[key]
      
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

print(cou)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

K = int(input())

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

print(res)

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a<b:
        tmp = a
        a = b
        b = tmp
    r = a % b
    while r!=0:
      a = b
      b = r
      r = a % b
    return b
  
def main():
    K = int(input())
    list_ = []
    sum_ = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            a = gcd(i,j)
            list_.append(a)
    for i in list_:
        for j in range(1,K+1):
            a = gcd(i,j)
            sum_ += a
    print(sum_)

main()

Submission status: Accepted

Solution code:
K=int(input())

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

s=0
for i in range(1,K+1):
    for j in range(i,K+1):
        m=gcd(i,j)
        for k in range(j,K+1):
            if i==j and j==k:
                s=s+gcd(m,k)
            elif i==j and j!=k:
                s=s+gcd(m,k)*3
            elif i!=j and j==k:
                s=s+gcd(m,k)*3
            else:
                s=s+gcd(m,k)*6
print (s)

Submission status: Accepted

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(math.gcd(a,b),c)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import gcd
def main():
    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)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from math import gcd

    K=int(input())
    cal=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):
                cal+=gcd(i,c)

    print(cal)


main()

Submission status: Accepted

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

ans = 0
for i in range(1,n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if i == j and j == k:
                ans += i
            
            elif len({i,j,k}) == 2:
                ans += math.gcd(math.gcd(i,j),k)*3
            
            elif len({i,j,k}) == 3:
                ans += math.gcd(math.gcd(i,j),k)*6
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math    

K = int(input())
ans = 0

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

Submission status: Accepted

Solution code:
def gcd(a, b):
  if b > a:
    temp = b
    b = a
    a = temp
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)
def sum_of_gcd(k):
  ans = 0
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      for k in range(1, k + 1):
        if i < j and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j < k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans
 
n = int(input())
print(sum_of_gcd(n))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import gcd

K = int(input())

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import itertools
from math import gcd
# def gcd(a,b):
#     x=max(a,b)
#     y=min(a,b)
#     if x%y==0:return y
#     else:
#         while(x%y!=0):
#             z=x%y
#             x=y
#             y=z
#         return z

# K = list(map(int, (stdin.readline().strip().split())))[0]
# i=[x for x in range(1,K+1)]
# j=[x for x in range(1,K+1)]
# k=[x for x in range(1,K+1)]
# num_list=set(map(tuple,(sorted(x) for x in (itertools.product(i,j,k)))))
#
# ans=0
# for i,j,k in num_list:
#     if i==j:
#         if j==k:
#             ans+=K
#         else:
#             ans+=gcd(i,gcd(j,k))*3
#     elif j==k:ans+=gcd(i,gcd(j,k))*3
#     else:ans+=gcd(i,gcd(j,k))*6
K = int(input())

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

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
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(gcd(a,b),c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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 += reduce(math.gcd, [a, b, c])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

K = int(input())
r = np.arange(1, K + 1)
print(np.sum(np.gcd.outer(np.gcd.outer(r, r), r)))

Submission status: Accepted

Solution code:
from math import gcd
from itertools import product
from functools import reduce

k = int(input())

ans = 0
for ptn in product(range(1, k + 1), repeat=3):
    ans += reduce(gcd, ptn)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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):
        x = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(x, c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())+1
sum_gcd = 0
def gcd(p,q):
    if p % q == 0:
        return q
    return gcd(q,p%q)
for a in range(1,K):
    sum_gcd += a
    for b in range(a+1,K):
        gcd_ab =gcd(a,b)
        sum_gcd += gcd_ab*6
        for c in range(b+1,K):
            sum_gcd +=gcd(gcd_ab,c)*6
print(sum_gcd)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

log = {}
K = int(input())
sum_gcd = 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(gcd(a, b), c)
print(sum_gcd)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
t = 0
import math
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: Accepted

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

Submission status: Accepted

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):
    x = gcd(i,j)
    for l in range(1,k+1):
      ans += gcd(x,l)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
t = 0
import math
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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

k = int(input())

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


K = int(input())

sum = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        sum += math.gcd(i, j)
        if j == K:
            break
        else:
            for k in range(j + 1, K + 1):
                sum += math.gcd(i, math.gcd(j, k)) * 2

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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


s = 0
n = int(input())


for i in range(1, n+1):
    for j in range(i+1, n+1):
        for k in range(j+1, n+1):
            s += gcd(gcd(i,j), k)

for i in range(1, n+1):
    for j in range(i+1, n+1):
        s += gcd(i, j)

s = s*6 + int(0.5 * n * (n+1))
print(s)

Submission status: Accepted

Solution code:
import math

k = int(input())
def ans():
    sum = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            for n in range(1,k+1):
                sum += math.gcd(math.gcd(l,m),n)
    return(sum)
print(ans())

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
from numba import jit

k = int(input())

@jit
def ans():
    sum = 0
    temp = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            temp = math.gcd(l,m)
            for n in range(1,k+1):
                sum += math.gcd(temp,n)
    return(sum)
print(ans())

Submission status: Accepted

Solution code:
import math

k = int(input())
def ans():
    sum = 0
    temp = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            temp = math.gcd(l,m)
            for n in range(1,k+1):
                sum += math.gcd(temp,n)
    return(sum)
print(ans())

Submission status: Accepted

Solution code:
import math
from numba import jit

k = int(input())

@jit
def ans():
    sum = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            for n in range(1,k+1):
                sum += math.gcd(math.gcd(l,m),n)
    return(sum)
print(ans())

Submission status: Accepted

Solution code:
K =int(input())
l = [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836,194157,207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813,10493367, 10611772,10813692]
print(l[K])

Submission status: Accepted

Solution code:
import math
#import fractions
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    #return reduce(fractions.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):
            abc_gcd = gcd_list([a,b,c])
            #print(a,b,c,abc_gcd)
            ans += abc_gcd

print(ans)

Submission status: Accepted

Solution code:
# 最小公倍数(ユーグリッド互除法)
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd( b, a % b)

K = int(input()) + 1
mydict = {}

# データパターンを求める式
ans = 0
for h in range(1, K):
  ans += gcd(h,gcd(h,h))

  for i in range(h+1, K):
    ans += (gcd(h,gcd(h,i)) * 3)
    ans += (gcd(h,gcd(i,i)) * 3)

    for j in range(i+1, K):
      ans += (gcd(h,gcd(i,j)) * 6)

print(ans)

Submission status: Accepted

Solution code:
k = int(input())

from math import gcd

#gcd_sum = [0] * 201
ans = 0

'''
for i in range(1, k+1):
    for j in range(1, k+1):
        gcd_sum[i] += gcd(i,j)
        #print(gcd(i,j))
        #print(gcd_sum[i])
'''
       
for a in range(1,k+1):
    for b in range(1,k+1):
        g = gcd(a,b)
        for c in range(1,k+1):
            ans += gcd(g,c)
        #print(g)
        #print(ans)

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


temp = 0
K = int(input())
sum = 0
for A in range(1,K+1):
    for B in range(1,K+1):
        temp = math.gcd(A,B)
        for C in range(1,K+1):
            sum = sum + math.gcd(temp,C)
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def gcd(n1,n2,n3):
    return math.gcd(math.gcd(n1,n2), n3)
    
ans = 0
K = int(input())
r = range(1, K+1)

print(sum([gcd(x1,x2,x3) for x1 in r for x2 in r for x3 in r ]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin, stdout
import math as m
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()

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

def main():
	k = int(rl())
	ans = 0
	for a in range(1, k+1):
		for b in range(1, k+1):
			for c in range(1, k+1):
				ans += tgcd(a, b, c)
	stdout.write(str(ans));stdout.write("\n")
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
k = int(input())

def gcd(x, y): 
    while(y): 
        x, y = y, x % y 
  
    return x

mat = [[0 for i in range(201)] for j in range(201)]

for i in range(201):
    for j in range(201):
        mat[i][j] = gcd(i, j)

sm = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sm += mat[mat[a][b]][c]

print(sm)

Submission status: Accepted

Solution code:
from math import gcd
from numba import njit

K = int(input())

@njit
def solve():
    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)
    return ans
print(solve())

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
from numba import njit
from math import gcd

K = int(input())

@njit
def solve():
    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(gcd(a, b), c)
    return ans

print(solve())

Submission status: Accepted

Solution code:
import math
d=0
k=int(input())
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):
            d+=math.gcd(x,c)
print(d)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
K=int(input())
 
result=[]
count=0
cnt=0
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
 
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans1=gcd(j,k)
      count=gcd(i,ans1)
      cnt+=count
      
print(cnt)

Submission status: Accepted

Solution code:
k=int(input())
l=[1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(l[k-1])