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

Solution (Python):
k=int(input())
z=range(1,k+1)
import math
from functools import reduce
sum=0
for i in z:
	for j in z:
		for jj in z:
			sum=sum+reduce(math.gcd,[i,j,jj])
print(sum)

Solution (Python):

import math


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


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

    total = 0
    temp = {}
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for l in range(1, k + 1):
                
                
                
                gcd_val = gcd(i, j, l)
                total += gcd_val

    return total


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

Solution (Python):
from itertools import (
    accumulate,  
    groupby,  
    permutations,  
    combinations,  
    product,  
    combinations_with_replacement,  
)

import fractions, math
from functools import reduce

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


N = int(input())
ans = 0
for i, j, k in combinations_with_replacement(range(1, N+1), 3):
    if i==j==k:
        ans += i
    elif i==j:
        ans += math.gcd(i, k)*3
    elif j==k:
        ans += math.gcd(j, i)*3
    elif i==k:
        ans += math.gcd(i, j)*3
    else:
        ans += gcd_list([i, j, k])*6
print(ans)

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

Solution (Python):
import math
from functools import reduce


k = int(input())

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

k += 1
ans = 0

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

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


print(ans)

Solution (Python):
import sys
import math
from collections import Counter, defaultdict, deque
from functools import reduce

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


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


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


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


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


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


def main():
    k = I()

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

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

    print(sum)


if __name__ == "__main__":
    main()

Solution (Python):
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):
            if i==j and j==k: ans+=i
            else:
                tmp = gcd(k, gcd(i,j))
                ans+=tmp
print(ans)

Solution (Python):
import math
from functools import reduce
import itertools
k = int(input())
a = [i for i in range(1,k+1)]
s =0

s = int(k*(k+1)/2)

for q in itertools.combinations(a,2):
  s += reduce(math.gcd,q)*3*2
for t in itertools.combinations(a,3):
  s += reduce(math.gcd,t)*6
print(s)

Solution (Python):
from math import gcd
from functools import lru_cache



def my_gcd(a, b):
    return gcd(a, b)


K = int(input())

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

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

            ans += gcd(g, k)
print(ans)

Solution (Python):
k = int(input())
a = [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]

s = a[k-1]

print(s)

Solution (Python):
import sys
import math
from collections import Counter, defaultdict, deque
from functools import reduce

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


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


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


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


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


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


def main():
    k = I()

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

    sum = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                if a == b or a == c:
                    sum += math.gcd(b, c)
                elif b == c:
                    sum += math.gcd(a, c)
                else:
                    sum += gcd(a, b, c)

    print(sum)


if __name__ == "__main__":
    main()

Solution (Python):
from functools import reduce

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

def gcdArr(a):
    return reduce(gcd, a)

n = int(input())
ret = 0
for a in range(1, n + 1):
    for b in range(1, n + 1):
        gcd_ = gcd(a, b)
        if gcd_ == 1:
            ret += n
            continue
        for c in range(1, n + 1):
            ret += gcd(gcd_, c)
print(ret)

Solution (Python):
import math
k = int(input())
count = 0
for i in range(1, k+1):
	for j in range(1, k+1):
		for u in range(1, k+1):
			count += math.gcd(math.gcd(i, j), u)
print(count)

Solution (Python):



def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
data_dict = {}
k = int(input())
if k == 1:
    print(1)
else:
    ans = 3 * k * k - 3 * k + 1
    for x in range(2, k - 1):
        for y in range(x + 1, k):
            key = str(x) + "-" + str(y)
            if key in data_dict:
                c = data_dict[key]
            else:
                c = gcd(x, y)
                data_dict[key] = c
            for z in range(y + 1, k + 1):    
                if c == 1:
                    ans += 6
                else:
                    key = str(c) + "-" + str(z)
                    if key in data_dict:
                        ans += data_dict[key] * 6
                    else:
                        d = gcd(c, z)
                        data_dict[key] = d
                        ans += d * 6
    for x in range(2, k):
        for y in range(x + 1, k + 1):
            key = str(x) + "-" + str(y)
            if key in data_dict:
                ans += data_dict[key] * 6
            else:
                d = gcd(x, y)
                data_dict[key] = d
                ans += d * 6
    for x in range(2, k + 1):
        ans += x

    print(ans)

Solution (Python):













import math

k = int(input())
sum = 0

for i in range(1, k+1):
	for j in range(1, i+1):
		for l in range(1, j+1):
			if i == j and j == l:
				sum += i
			elif i == j or j == l:
				a = math.gcd(i, j)
				b = math.gcd(j,l)
				g = math.gcd(a,b)
				sum += g*3

			else:
				a = math.gcd(i, j)
				b = math.gcd(j,l)
				g = math.gcd(a,b)
				sum += g*6

print(sum)

Solution (Python):
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
def calc_same_num(s):
    if s[0]==s[1] and s[1]==s[2]:
        return 1
    elif s[0]==s[1] or s[1]==s[2]:
        return 3
    else:
        return 6
    
k = int(input())
sum_check = 0
a,b,c = 1,1,1
ans = 0
while a<=k and b<=k and c<=k:
    gcd = gcd_list([a,b,c])
    ans += gcd*calc_same_num([a,b,c])
    if c<k:
        c += 1
    elif b<k:
        b += 1
        c = b
    else:
        a += 1
        b = a
        c = a
print(ans)

Solution (Python):
def gcd(x,y):
    r = x % y
    while r != 0:
        x,y = y,r
        r = x % y
    return(y)

summ = 0
K = int(input())
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if a == b:
                if b == c:
                    summ += gcd(gcd(a,b),c)
                else:
                    summ += 3 * gcd(gcd(a,b),c)
            elif a == c or b == c:
                summ += 3*gcd(gcd(a,b),c)
            else:
                summ += 6*gcd(gcd(a,b),c)
print(summ)

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

sum_1 = 0
for a in range(3,K+1):
    for b in range(2, a):
        for c in range(1, b):
            sum_1 += math.gcd(math.gcd(a, b), c)

sum_1 = sum_1 * 6

sum_2 = 0
for a_b in range(2, K+1):
    for c in range(1, a_b):
        sum_2 += math.gcd(a_b, c)

sum_2 = sum_2 * 6

sum_3 = 0
for i in range(1, K+1):
    sum_3 += i


print(sum_1 + sum_2 + sum_3)

Solution (Python):
from collections import defaultdict

def yakusuu(i):
    res = list()
    for j in range(1, i+1):
        if i % j == 0:
            res.append(j)
    return res


k = int(input())

x = [[]]
for i in range(1, k+1):
    x.append(yakusuu(i))

s = 0
for i in range(1, k+1):
    for j in range(1, k + 1):
        y = list()
        for xx in x[i][-1::-1]:
            if xx in x[j]:
                y.append(xx)
        for k in range(1, k+1):
            for xx in y:
                if xx in x[k]:
                    s += xx
                    break

print(s)

Solution (Python):
from math import gcd

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

if __name__ == '__main__':
  main()

Solution (Python):
import math

K=int(input())

f=[]

for i in range(1,K+1):
  for j in range(1,K+1):
    s=math.gcd(i, j)
    f.append(s)

S=0
for i in range(1,K+1):
  for j in f:
    S+=math.gcd(i,j)

print(S)

Solution (Python):
import math


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

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

    print(c)

main()

Solution (Python):
from math import gcd as g
n=int(input())
ans=n*(n+1)//2
for i in range(1,n):
  for j in range(i+1,n+1):
    ans+=6*g(i,j)
for i in range(1,n-1):
  for j in range(i+1,n):
    x=g(i,j)
    for k in range(j+1,n+1):
      ans+=6*g(x,k)
print(ans)

Solution (Python):
import math
from functools import reduce

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

K = int(input())
three = 0
six = 0
same = 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 and a != c):
        six += gcd(a,b,c)
      elif(a == b and b == c and c == a):
        same += a
      else:
        three += gcd(a,b,c)

print(six * 6 + three * 3 + same)

Solution (Python):
from fractions import gcd
from collections import defaultdict


def main():
    K = int(input())
    d = defaultdict(int)
    ans = 0
    for i in range(K):
        for j in range(K):
            g = gcd(i + 1, j + 1)
            d[g] += 1
    for g in d.keys():
        for i in range(K):
            ans += gcd(g, i + 1) * d[g]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
K=int(input())
GCD=[[0]*(K+2) for _ in range(K+2)]
import math
def make_GCD(K):
    for a in range(1,K+1):
        for b in range(1,K+1):
            GCD[a][b]=math.gcd(a,b)            
make_GCD(K)

def gcd3(a,b,c):
    a=GCD[a][b]
    return GCD[a][c]
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)            
print(ans)

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

K = int(input())
q = []
r = []
for i in range(1,K+1):
    for j in range(1,K+1):
        q.append(gcd(i,j))
for i in range(1,K+1):
    for j in q:
        r.append(gcd(i,j))
print(sum(r))

Solution (Python):
import math

m = int(input())
a = (m * (m + 1)) // 2
b = 0
c = 0
for i in range(m):
    for j in range(i + 1, m):
        b += math.gcd(i + 1, j + 1)
for i in range(m):
    for j in range(i + 1, m):
        l = math.gcd(i + 1, j + 1)
        for k in range(j + 1, m):
            c += math.gcd(l, k + 1)
print(a + b * 6 + c * 6)

Solution (Python):
import math

n=int(input())

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

Solution (Python):
from math import gcd

k = int(input())
range(1, k+1)

l1 = range(1, k+1)
def loop(s):
    for a in l1:
        for b in l1:
            for c in l1:
                l2 = (a, b, c)
                g1 = gcd(a,b)
                g2 = gcd(g1, c)
                s += g2
    return s

print(loop(0))

Solution (Python):


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, gcd

from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    K = intinput()

    total = 0
    memo = [ [-1] * (K+1) for _ in range(K+1)]
    for a in range(1,K+1):
        for b in range(a, K+1):
            val = gcd(a,b)
            memo[a][b] = val
            memo[b][a] = val
            memo[a][val] = val
            memo[b][val] = val
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                total += memo[memo[a][b]][c]
    print(total)

Solution (Python):
from collections import defaultdict
def gcd(m,n):
    if n==0:
        return m
    return gcd(n,m%n)

k=int(input())
t=0
for i in range(1,k+1):
    for j in range(1,k+1):
        g=gcd(i,j)
        for k in range(1,k+1):
            if k%g==0:
                t+=g
            elif g%k==0:
                t+=k
            else:
                t+=gcd(g,k)
print(t)

Solution (Python):
import math

N = int(input())
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==k:
                ans+=math.gcd(math.gcd(i,j),k)
            elif i!=j!=k:
                ans+=math.gcd(math.gcd(i,j),k)*6
            else:                
                ans+=math.gcd(math.gcd(i,j),k)*3

print(int(ans))

Solution (Python):
k = int(input())
import math
l = []
ans = 0
e = 0
d = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        e = math.gcd(a,b)
        for c in range(b,k+1):
            d = math.gcd(e,c)
            if a != b and b!= c and a!= c:
                ans+= d*6
            elif (a==b and a!=c) or (a==c and a!= b) or (b == c and a!= b):
                ans+= d*3
            else:
                ans+= d
print(ans)

Solution (Python):
import math as np
K=int(input())
P=0
for i in range(1,K+1):
    for j in range(1,K+1):
        l=np.gcd(i,j)

        for k in range(1,K+1):
            m=np.gcd(l,k)
            P=m+P
print(P)

Solution (Python):
import math
N = int(input())
 
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))
        
print(ans)

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

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

N = int(input())
count = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            l=gcd3(i,j,k)
            count += l
print(count)

Solution (Python):
from functools import reduce
import math

N = int(input())
sum = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

Solution (Python):
import numpy as np

K =int(input())


ans = 0

dim2 = [[1]*K for i in range(K)]
for i in range(K):
    for j in range(K):
        dim2[i][j] = np.gcd(i+1,j+1)

def row_s(n):
    s = 0
    for i in range(K):
        s = s + dim2[n-1][i]
    return s

for k in range(1,K+1):
    c = 0
    for i in range(K):
        c = c + dim2[i].count(k)
    ans = ans + c * row_s(k)

print(ans)

Solution (Python):
k = int(input())
li=[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(li[k-1])

Solution (Python):
import math

def main():
  k = int(input())
  params = [1,1,0]
  count = 0
  
  while params[0] < k or params[1] < k or params[2] < k:
    if params[2] < k:
      params[2] = params[2]+1
    elif params[1] < k:
      params = [params[0],params[1]+1,1]
    elif params[0] < k:
      params = [params[0]+1,1,1]
      
    tmp = 0
    if 1 in params:
      tmp = 1
    else:
      tmp = math.gcd(params[0],params[1])
      if tmp > 1:
        tmp = math.gcd(tmp, params[2])
    
    count += tmp
    
  return count
 
def gcd(val1, val2):
  val3 = 0
  while True:
    val3 = val1 % val2
    val1 = val2
    if val3 == 0:
      break
    val2 = val3
  return val1

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

Solution (Python):
import math
from functools import reduce

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

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(x,y,z)
            
print(ans)

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

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

print(ans)

Solution (Python):
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
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,j,k)

print(ans)

Solution (Python):
import math
from functools import reduce

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

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

Solution (Python):
def _gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a

def gcd(a, b, c):
    return _gcd(_gcd(a, b), c)

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

Solution (Python):
import itertools
import math
n = int(input())

lst = [_ for _ in range(1, n+1)]
lst2 = list(itertools.product(lst, repeat=2))

lst3 = [math.gcd(_[0], _[1]) for _ in lst2]

lst4 = list(itertools.product(lst3, lst))

lst5 = [math.gcd(_[0], _[1]) for _ in lst4]

print(sum(lst5))

Solution (Python):
from fractions import gcd
k = int(input())
result = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        temp = gcd(i, j)
        work = temp
        for j in range(1, temp):
            work += gcd(j, temp)
        result += k//temp * work
        for j in range(1, k%temp+1):
            result += gcd(j, temp)
print(result)

Solution (Python):
K = int(input())
s = 0
def gcd(a,b):
    if a == 1 or b == 1:
        return 1
    elif a == 0 or b == 0:
        return max(a,b)
    else:
        if a > b:
            return gcd(a%b,b)
        else:
            return gcd(a,b%a)
for i in range (1,K + 1):
    for j in range (i + 1,K + 1):
        x = gcd(i,j)
        for k in range (j + 1,K + 1):
            s = s + 6 * gcd(x,k)
for i in range(1,K + 1):
    for j in range (i + 1,K + 1):
        s = s + 6 * gcd(i,j)
                    
for i in range(1,K + 1):
    s = s + i

print(s)

Solution (Python):
import math
from functools import reduce

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

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

k=int(input())
sum=0
for i in range(1,k+1):
    for j in range(i+1,k+1):
        for k in range(j+1,k+1):
            
            
            sum+=gcd(i,j,k)*3*2
for i in range(1,k+1):
    for j in range(i+1,k+1):
            
            
            sum+=gcd(i,j,j)*3*2
for i in range(1,k+1):
        
        
        sum+=gcd(i,i,i)
print(sum)

Solution (Python):
from math import gcd
k = int(input())
li = []
li2 = [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]
cnt = 0
if k < 170:
    for i in range(1, k + 1):
    	for j in range(1, k + 1):
            for l in range(1, k + 1):
        	    li.append(gcd(gcd(i, j), gcd(j, l)))
    print(sum(li))
else:
    print(li2[k - 170])

Solution (Python):
K = int(input())







import math
import itertools


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


def calculate(k):
    sum = 0
    for i in itertools.combinations([i for i in range(1,k+1)],2):
        val1 = common(i[0],i[1]) * 6
        sum = sum + val1

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

    for  i in itertools.combinations([i for i in range(1,k+1)],3):
        val1 = common(i[0],i[1])
        val2 = common(val1,i[2])
        sum = sum + val2*6


    print(sum)




calculate(K)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

K = int(input())

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

print(answer)

Solution (Python):
from math import gcd



k = int(input())
ans = 0

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

import collections
c = collections.Counter(temp)

for i in range(1,k+1):
  for j in c.keys():
    ans += gcd(i,j) * c[j]

print(ans)

Solution (Python):
from math import gcd
K = int(input())
answer = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            answer+= gcd(gcd(a,b),c)
print(answer)

Solution (Python):

K = int(input())
import math

ans = 0
for i in range(K):
    for k in range(K):
        x = math.gcd(i+1,k+1)
        if x==1:
            ans +=K
        else:
            for l in range (K):
                ans += math.gcd(x, l+1)
            
print(int(ans))

Solution (Python):
from functools import reduce
import math




a = int(input())
result = 0

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

Solution (Python):
K=int(input())

import itertools,math
from functools import reduce

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

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

ans = 0
for a,b,c in itertools.product(data, repeat=3):
    ans += gcd(a,b,c)
print(ans)

Solution (Python):






import sys
sys.setrecursionlimit(10000000)


dxdy=((1,0),(0,1))

def pin(type=int):
    return map(type,input().rstrip().split())
from math import gcd 
def resolve():  
    N=int(input())
    N=N
    r=range(1,N+1)
    ans=0
    for a in r:
        for b in r:
            t= gcd(a,b)
            for c in r:
                ans+= gcd(t,c)
    print(ans)
"""         


"""
"""
お前カッコ閉じ,るの忘れてるだろ
"""
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)


if __name__ == "__main__":
    

    resolve()

Solution (Python):
import math
ans = 0
N = int(input())
if N <= 5:
  for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
else:
    for i in range(N):
        ans += i+1
    for i in range(N-1):
        for j in range(i+1,N):
            ans += 6*math.gcd(i+1,j+1)
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                ans += 6*math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
print(ans)

Solution (Python):
import math
from functools import reduce

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

k = int(input())
t = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if math.gcd(i,j) ==1:
            t += 1*len(list(range(1,k+1)))
        else:
            for l in range(1,k+1):
                    t += gcd(i,j,l)
print(t)

Solution (Python):
import math
from functools import reduce
from itertools import product
K=int(input())
gcd=0.
for i in range(K):
    for j in range(K):
        a=math.gcd(i+1,j+1)
        for k in range(K):
            gcd+=math.gcd(a,k+1)
print(int(gcd))

Solution (Python):
import math
from functools import reduce
import numpy as np
from itertools import combinations
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

s = int(input())
qwe = np.arange(s+1)

sum = (1+s)*s/2

for i in range(1, s+1):
    for j in range(i + 1, s+1):
        sum += gcd(i, j, j) * 3
        sum += gcd(i, i, j )* 3
        
        for k in range(j + 1, s+1):
            sum += gcd(i, j, k) * 6
            
print(int(sum))

Solution (Python):
import math
def I(): return int(input())

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