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

Submission status: Accepted

Solution code:
import math
k = int(input())
s = 0
b = []
for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            p = len(set([i,j,l]))
            if p ==1:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q
                b.append(q)
            elif p ==2:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q*3
                b.append(q)
            else:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q*6
                b.append(q)
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):
    for c in range(1,k+1):
      ans += gcd(gcd(a,b),c)

print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
# import math
import sys
import collections

from math import gcd
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(input())
""" answer 1
ans = 0
tmp = {}
for i in range(201):
    tmp[i] = 0

for i in range(1, K +1):
    for j in range(1, K +1):
        tmp[math.gcd(i, j)] += 1

for k in range(1, K +1):
    for key in tmp.keys():
        ans += math.gcd(key, k) * tmp[key]
print(ans)

"""


"""answer 2　ぎりぎり
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)

"""

ans = 0

# (1,2,3)
for i in range(1, K +1):
    for j in range(i+ 1, K + 1):
        for k in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), k) * 6

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

# (1,1,1)
for i in range(1, K +1):
    ans += i
print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
# import math
import sys
import collections

from math import gcd
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(input())
""" answer 1
ans = 0
tmp = {}
for i in range(201):
    tmp[i] = 0

for i in range(1, K +1):
    for j in range(1, K +1):
        tmp[math.gcd(i, j)] += 1

for k in range(1, K +1):
    for key in tmp.keys():
        ans += math.gcd(key, k) * tmp[key]
print(ans)

"""

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:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(input())


ans = 0

tmp = {}
for i in range(201):
    tmp[i] = 0

for i in range(1, K +1):
    for j in range(1, K +1):
        tmp[math.gcd(i, j)] += 1

for k in range(1, K +1):
    for key in tmp.keys():
        ans += math.gcd(key, k) * tmp[key]
print(ans)

"""
K = 3

1 1 1  1
1 1 2  1
1 1 3  1
1 2 1  1
1 2 2  1
1 2 3  1
2 1 1  1
2 1 2  1
2 1 3  1
3 1 1  1
3 1 2  1
3 1 3  1
3 2 1  1
3 2 2  1
3 2 3  1
3 3 1  1
3 3 2  1
3 3 3  3

"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
K = int(input())
a = np.arange(1,K+1) 
b = np.gcd.outer(np.gcd.outer(a,a),a)
c = b.sum()
print(c)

Submission status: Accepted

Solution code:
import itertools
import math

k = int(input())
b = []
for i in range(1,k+1):
    b.append(i)
a = list(itertools.combinations_with_replacement(b, 3))
c = 0
for i in a:
    if (i[0]==i[1] or i[1]==i[2]):
        if (i[0]==i[1] and i[1]==i[2]):
         c += math.gcd(math.gcd(i[0],i[1]),i[2])
        else:
            c += 3* math.gcd(math.gcd(i[0],i[1]),i[2])
    else:
        c += 6*math.gcd(math.gcd(i[0],i[1]),i[2])

print(c)

Submission status: Accepted

Solution code:
import math
k = int(input())
ans = 0
def gcd(a, b, c):
    p = math.gcd(a, b)
    return math.gcd(p, c)

for i in range(1, k+1):
    for j in range(i, k+1):
        for l in range(j, k+1):
            if i == j and j == l:
                ans += i
            elif i==j or j==l or l==i:
                ans += 3*gcd(i, j, l)
            else:
                ans += 6 * gcd(i, j, l)
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):
        s=math.gcd(a,b)
        for c in range(1,k+1):
            t=math.gcd(s,c)
            ans+=t
print(ans)

Submission status: Accepted

Solution code:
import math

K = int(input())

ans = 0
memo = {}
for a in range(1, K+1):
    for b in range(1, K+1):
        gcd_ab = math.gcd(a, b)
        try:
            memo[gcd_ab] += 1
        except:
            memo[gcd_ab] = 1


for c in range(1, K+1):
    for key in memo.keys():
        ans += math.gcd(c, key) * memo[key]

print(ans)

Submission status: Accepted

Solution code:
import math

def calc(N):
    gcd = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

    for i in range(1,N + 1):
        for j in range(i,N + 1):
            gcd[i][j] = math.gcd(i,j)
            gcd[j][i] = gcd[i][j]

    ans = 0
    for i in range(1,N + 1):
        for j in range(1,N + 1):
            for k in range(1,N + 1):
                g = gcd[i][j]
                ans += gcd[g][k]
    return ans


N = int(input())

print(calc(N))

Submission status: Accepted

Solution code:
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

Submission status: Accepted

Solution code:
import numpy as np
 
K=int(input())
 
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print(nums.sum())

Submission status: Accepted

Solution code:
import math
import itertools

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

K = int(input())
abc = itertools.combinations_with_replacement(list(range(1,K+1)),3)

ans = 0
for a,b,c in abc:
    p = len(set([a,b,c]))
    if p==1:
        ans += gcd(a,b,c)
    elif p==2:
        ans += gcd(a,b,c) * 3
    else:
        ans += gcd(a,b,c) * 6
print(ans)

Submission status: Accepted

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

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:
def gcd(a,b):
    if dp[a][b]==-1:
        if b==0:
            return a
        else:
            ans=gcd(b,a%b)
            dp[a][b]=ans
            return ans
    else:
        return dp[a][b]

K=int(input())

dp=[[-1 for i in range(K+1)] for j in range(K+1)]

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

print(total)

Submission status: Accepted

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

for a in range(1, k+1):
    for b in range(a+1, k+1):
        d += 6*gcd(a,b)

for a in range(1, k+1):
    d += a
print(d)

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

Submission status: Accepted

Solution code:
import math
from collections import defaultdict

k = int(input())

d = defaultdict(int)
for a in range(1, k+1):
	for b in range(1, k+1):
		d[math.gcd(a,b)] += 1
n = 0
for c in range(1, k+1):
	for g in d:
		n += math.gcd(c, g) * d[g]
			
print(n)

Submission status: Accepted

Solution code:
import math
import collections

K = int(input())

# intで初期化するため0が返る
cnt = collections.defaultdict(int)
for i in range(1, K + 1):
    for j in range(1, K + 1):
        key = math.gcd(i, j)
        # 最大公約数をkeyにし、同じ最大公約数の出現回数を保持
        cnt[key] = cnt[key] + 1

total = 0
for k in range(1, K + 1):
    for key in cnt.keys():
        # 出現済みの最大公約数との最大公約数を取り、出現回数分を加算する
        total = total + math.gcd(k, key) * cnt[key]

print(total)

Submission status: Accepted

Solution code:
from math import gcd    
K=int(input())
S=0

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

print(S)

Submission status: Accepted

Solution code:
from math import gcd
from itertools import product

K = int(input())

print(sum(gcd(gcd(a, b), c) for a, b, c in product(range(1, K + 1), repeat=3)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı?
# memnün oldum
import sys
import math


sys.setrecursionlimit(10 ** 8)

#def divmin
#for i in range(d, 1, -1):
#    if(d % i == 0):
#        print(i)
def pgcd(a, b):
    while b!=0:
        a,b=b,a%b
    return a

def msum(a, b, c):
    if (a <= b) and (a <= c): 
        return math.gcd(a, math.gcd(b,c))
        #while(a >= 1):
        #    if (b % a == 0) and (c % a == 0):
        #        return a
            
    elif (b <= a) and (b <= c):
        return(math.gcd(b, math.gcd(a,c)))
    elif (c <= a) and (c <= b):
        return math.gcd(c, math.gcd(a,b))
    else:
        print("Grande érreur dans ta tête!!!")

def çözmek(num):
    csum = 0
    for i in range(1, num+1):
        for j in range(1, num+1):
            for l in range(1, num+1):
                #print(i,j,l)
                #csum += msum(i,j,l)
                csum += math.gcd(i, math.gcd(j,l))

    return csum


if __name__ == "__main__":
    K = int(input())
    print(çözmek(K))

Submission status: Accepted

Solution code:
import math


def main():
    k = int(input())
    k1 = k + 1

    sum = 0
    for i in range(1, k1):
        for j in range(1, k1):
            for m in range(1, k1):
                sum += math.gcd(math.gcd(i, j), m)
    print(sum)

main()

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

Submission status: Accepted

Solution code:
import math


def main():
    k = int(input())
    k1 = k + 1

    sum = 0
    for i in range(1, k1):
        for j in range(1, k1):
            for m in range(1, k1):
                sum += math.gcd(math.gcd(i, j), m)
    print(sum)

main()

Submission status: Accepted

Solution code:
import math
k = int(input())
n = []
for a in range(1, k+1):
  for b in range(1, k+1):
    d = math.gcd(a,b)
    n.append(d)
m = []
for d in n:
  for c in range(1, k+1):
    e = math.gcd(d,c)
    m.append(e)
    
print(sum(m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=0
k=int(input())
from math import gcd
from itertools import product
L=product([i for i in range(1,k+1)],repeat=2)
S=[gcd(a,b) for (a,b) in L]
from collections import Counter
S_counter=Counter(S)
for key,value in S_counter.items():
    for i in range(1,k+1):
        s+=gcd(key,i)*value
print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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())
from math import gcd

samu = 0

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


print(samu)

Submission status: Accepted

Solution code:
import math

count = 0

K = int(input())
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):
            count += math.gcd(temp, c)

print(count)

Submission status: Accepted

Solution code:
from math import gcd 

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

print(mysum)

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
k = int(input())
 
cnt = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            cnt += gcd(i,j,m)
            
 
print(cnt)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

for i in range(1,K+1):
  count += i
      
print(count)

Submission status: Accepted

Solution code:
from math import gcd


def main():
    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(gcd(i, j), l)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    return gcd(b, a % b)


def main():
    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(gcd(i, j), l)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
from math import gcd
def main():
    #入力
    readline=stdin.readline
    k=int(readline())
    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)
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
k = int(input())

def gcd(p, q):
    if p%q==0:
        return q
    else:
        return gcd(q, p%q)

h=1
ans=0
while h<=k:
    i=1
    while i<=k:
        j=1
        while j<=k:
            ans += gcd(gcd(h,i),j)
            j+=1
        i+=1
    h+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

K = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import math

def gcd(*numbers):
    return math.gcd( math.gcd(a, b), c)

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
k = int(input())

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

ans = 0

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

for a in range(1,k+1):
    for b in range(1,k+1):
        if a!=b:
            ans += 3*gcd(a,a,b)

for a in range(1,k-1):
    for b in range(a+1,k):
        for c in range(b+1,k+1):
            #if a!=b and a!=c and b!=c:
            ans +=6*gcd(a,b,c)


print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
s=0
q=0
w=0
e=0
for i in range(K):
    q+=gcd(i+1,i+1,i+1)
    
for a in range(K):
    for b in range(K):
        if not a==b:
            w+=3*gcd(a+1,a+1,b+1)
for a in range(1,K-1):
    #print(a)
    for b in range(a+1,K):
     #   print(b)
        for c in range(b+1,K+1):
      #      print(c)
            e+=6*gcd(a,b,c)
#print(q,w,e)     
print(q+w+e)

Submission status: Accepted

Solution code:
import time
def gcd1(x,y):
    d = x % y
    while d != 0:
        x,y = y,d
        d = x % y
    return y

def gcd(x,y):
    if x == 1 or y == 1:
        return 1
    if x < y:
        x,y = y,x
    return gcd1(x,y)

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

K = int(input())
t1 = time.time()
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd3(a,b,c)
t2 = time.time()
print(ans)
#

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
from math import gcd
def main():
    K = int(input())
    a = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            a.append(gcd(i, j))
    count = 0
    for i in range(1, K+1):
        for j in range(len(a)):
            count += gcd(i, a[j])
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math, itertools
K = int(input())
#K = 2

a = [i for i in range(1,K+1)]

x = itertools.combinations(a,2)
y = itertools.combinations(a,3)

c = 0
for i,j in x:
  c += math.gcd(i,j)

d = 0
for i,j,k in y:
  d += math.gcd( math.gcd(i,j) , k)

ans = sum(a) + c*6 + d*6

if K == 1:
  ans = 1
elif K == 2:
  ans = 9

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

K = int(input())
total = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            total += gcd(gcd(a,b),c)
print(total)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

K = int(input())
total = 0
for a in range(K):
    for b in range(K):
        for c in range(K):
           total += gcd(a+1,b+1,c+1)
print(total)

Submission status: Accepted

Solution code:
import math
g = 0
K = int(input())
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            g += math.gcd(math.gcd(a,b),c)*6
for d in range(1,K):
    for e in range(d+1,K+1):
        g+= math.gcd(d,e)*6
g+= K*(K+1)//2
print(g)

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 itertools import product
from math import gcd

K = int(input())

print(sum([gcd(gcd(a, b), c) for a, b, c in product(range(1, K + 1), repeat=3)]))

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

def ep(*params):
    print(*params,file=sys.stderr)

def gcd(s1,s2):
    s = (s1,s2)
    global total,hit
    return math.gcd(s1,s2)
    
K = int(input().rstrip())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        ab = gcd(a,b)
        if ab == 1:
            ans += 1*K
        else:
            for c in range(1,K+1):
                ans += gcd(ab,c)

print(ans)

Submission status: Accepted

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 a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += gcd(a,b,c)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

K = int(input())

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        gcd2 = math.gcd(a, b)
        for c in range(1, K + 1):
            gcd = math.gcd(gcd2, c)
            Sum.append(gcd)

print(sum(Sum))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
import math
from functools import reduce
G = []
for a in range(1,K+1):
    for b in range(1,K+1):
        g = math.gcd(a,b)
        for c in range(1,K+1):
            gc = math.gcd(g,c)
            G.append(gc)
print(sum(G))

Submission status: Accepted

Solution code:
from math import gcd

k = int(input())
total = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        t = gcd(a, b)
        for c in range(1, k+1):
            # print(a, b, c, gcd(a, gcd(b, c)))
            total += gcd(t, c)
print(total) # sample_02 1982 ms

Submission status: Accepted

Solution code:
# ABC162C

from fractions import gcd
from math import gcd

k = int(input())
total = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            # print(a, b, c, gcd(a, gcd(b, c)))
            total += gcd(a, gcd(b, c))
print(total)

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):
        a = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(a, k)
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:
import math
K = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import math

K = int(input())

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

k = int(input())
hi_gcd = 1
gcd = 1
ans = 0

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

print(ans)

Submission status: Accepted

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

K = int(input())

sum = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i == j and j==k:
                sum += i
            elif i == j or j == k or k == i:
                sum += 3*gcd(i,j,k)
            else:
                sum += 6*gcd(i,j,k)

print(sum)

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):
      tmp = math.gcd(a,b)
      tmp = math.gcd(tmp,c)
      ans += tmp
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):
     for l in range(1,k+1):
        Sum += math.gcd(math.gcd(i,j),l)

print(Sum)

Submission status: Accepted

Solution code:
from math import gcd

K = int(input())
cnt = 0

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

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement
import math
from functools import reduce

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

sum = 0
k = int(input())
l = range(1,k+1)

for a,b,c in combinations_with_replacement(l, 3):
    ans = gcd(a,b,c)
    if a == b and a == c:
        sum += ans
    elif a == b or b == c or c == a:
        sum += 3 * ans
    else:
        sum += 6 * ans

print(sum)

Submission status: Accepted

Solution code:
K = int(input())

import math

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

print(ans)

Submission status: Accepted

Solution code:
from math import gcd
K = int(input())
l = 0
for A in range(1, K + 1):
  for B in range(1, K + 1):
    for C in range(1, K + 1):
      l += gcd(gcd(A,B), C)
      
print (l)

Submission status: Accepted

Solution code:
import math

def main():
        K = int(input())

        total = 0

        for a in range(1,K+1):
                if a==1:
                        total += 1*K*K
                else:
                        for b in range(1,K+1):
                                if b==1:
                                        total += 1*K
                                else:
                                        for c in range(1,K+1):
                                                total += math.gcd(math.gcd(a,b),c)

        print("{}".format(total))

if __name__=="__main__":
        main()

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce
def gcds(*numbers):
  return reduce(gcd, numbers)
K = int(input())
ans1 = 0
ans2 = 0
ans3 = 0
for a in range(1, K + 1):
  for b in range(a, K + 1):
    for c in range(b, K + 1):
      if a == b and b == c:
        ans1 += gcds(a, b, c)
      elif a == b or b == c or c == a:
        ans2 += gcds(a, b, c)
      else:
        ans3 += gcds(a, b, c)
print(ans1 + 3 * ans2 + 6 * ans3)

Submission status: Accepted

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

Submission status: Accepted

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

print(answer)

Submission status: Accepted

Solution code:
import math

def gcd(k):
  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)  
  
if __name__ == "__main__":
  k = int(input())
  gcd(k)