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):
import math
from functools import reduce
K = int(input())



def gcd_base(x, y):
    return math.gcd(x, y)



def gcd_list(numbers):
    return reduce(gcd_base, numbers)


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

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

Solution (Python):

import math
from functools import reduce

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

k = int(input())

ans = 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:
                ans += gcd_list([a, b, c])
            elif a!=b and b!=c:
                ans += gcd_list([a, b, c]) * 6
            else:
                ans += gcd_list([a, b, c]) * 3
print(ans)

Solution (Python):
from math import gcd
k = int(input())
res = [0]*201
for i in range(1,k+1):
    for j in range(1,k+1):
        res[gcd(i,j)]+=1
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans += gcd(i,j)*res[i]

print(ans)

Solution (Python):
import math
import itertools

from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]









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

	s=0
	for a,b,c in itertools.combinations(range(1,k+1), 3):
		g=math.gcd(math.gcd(a,b),c)
		g*=6
		s+=g
	for a,b in itertools.combinations(range(1,k+1), 2):
		g=math.gcd(a,b)
		g*=6
		s+=g
	for a in range(1,k+1):
		g=a
		s+=g
	print(s)
	
	
if __name__=="__main__":

	main()

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

Solution (Python):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from math import gcd
n=n0()
s=0
for a in range(1,n+1):
    for b in range(a,n+1):
        for c in range(b,n+1):
            if a==b==c:
                s+=gcd(gcd(a,b),c)
            elif a==b or b==c:
                s+=3*gcd(gcd(a,b),c)
            else:
                s+=6*gcd(gcd(a,b),c)
print(s)

Solution (Python):
import math

K = int(input())

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)

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

Solution (Python):

from math import gcd

K=int(input())
ans=0
memo=[[[-1 for i in range(K+1)] for j in range(K+1)] for k in range(K+1)]

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if memo[i][j][k]==-1:
                v=gcd(i,gcd(j,k))
                memo[i][j][k]=v
                memo[i][k][j]=v
                memo[j][k][i]=v
                memo[j][i][k]=v
                memo[k][i][j]=v
                memo[k][j][i]=v
            else:
                v=memo[i][j][k]
            ans+=v

print(ans)

Solution (Python):
from math import gcd
K = int(input())
ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for h in range(1,K+1):
      x = gcd(i,j)
      y = gcd(x,h)
      ans += y
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)

K = int(input())
answer = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for h in range(1,K+1):
            answer += gcd(i,j,h)
print(answer)

Solution (Python):
from fractions import gcd

k = int(input())
s = 0
mem = {}
for a in range(1, k + 1):
    for b in range(1, k + 1):
        if mem.get((a, b)) is None:
            g = gcd(a, b)
            mem[(a, b)] = g
            mem[(b, a)] = g
        else:
            g = mem[(a,b)]            
        for c in range(1, k + 1):
            if mem.get((g, c)) is None:
                h = gcd(g, c)
                mem[(g, c)] = h
                mem[(c, g)] = h
                s += h
            else:
                s += mem[(g, c)]
print(s)

Solution (Python):
from itertools import combinations_with_replacement, permutations

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

def main():
    K = int(input())
    ans = 0
    for i in range(K):
        for j in range(K):
            for k in range(K):
                temp = gcd(i+1, j+1)
                temp = gcd(temp, k+1)
                ans += temp
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
import math
x = int(input())
ans = 0
memo = {}
for i in range(1, x+1):
    for j in range(1, x+1):
        a,b = min(i,j), max(i,j)
        if (a,b) in memo.keys():
            l = memo[(a,b)]
        else:
            l = math.gcd(a,b)
            memo[(a,b)] = l
        for k in range(1, x+1):
            ans += math.gcd(l,k)
print(ans)

Solution (Python):
import math

k = int(input())

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        _gcd = math.gcd(a, b)

        if _gcd == 1:
            ans += k
        else:
            for c in range(1, k + 1):
                ans += math.gcd(_gcd, c)

print(ans)

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


def gcd_lst(numbers):
    return reduce(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):
            ans += gcd_lst([a, b, c])
print(ans)

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    k = int(input())
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    res = 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==c:
                    res += gcd_group([a,b,c]) 
                elif a==b or b==c or a==c:
                    res += gcd_group([a,b,c]) * 3
                else:
                    res += gcd_group([a,b,c]) * 6
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
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)

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

ans = 0

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

Solution (Python):
import math

K = int(input())

table = [[math.gcd(a, b) for a in range(K + 1)] for b in range(K + 1)]

gcd_count = [0] * 201

for a in range(1,K + 1):
    for b in range(1,K + 1):
        gcd_count[table[a][b]] += 1

ans = 0

for ab in range(1,K + 1):
    for c in range(1,K + 1):
        ans += gcd_count[ab] * table[ab][c]

print(ans)

Solution (Python):
import math

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

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

memo = [[-1 for _ in range(k+1)] for _ in range(k+1)]


def gcd(a, b):
    if -1 != memo[a][b]:
        return memo[a][b]
    r = a % b
    if r == 0:
        memo[a][b] = b
        return b
    else:
        ans = gcd(b, r)
        memo[a][b] = ans
        return ans


def gcd_m(a, b, c):
    lst = sorted([a, b, c], reverse=True)
    return gcd(gcd(lst[0], lst[1]), lst[2])


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

Solution (Python):
k = int(input())
from math import gcd

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)

Solution (Python):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

K = int(input())

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

Solution (Python):
import math
from functools import reduce

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

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

    sum_count = 0
    for i in range(1,n+1):
        tmp_list = []
        tmp_list.append(i)
        for j in range(1,n+1):
            tmp_list.append(j)
            for k in range(1,n+1):
                tmp_list.append(k)              
                sum_count += gcd_list(tmp_list)
                tmp_list.pop(2)
            tmp_list.pop(1)

    print(sum_count)        

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

K = int(input())
K += 1
ans = 0
for i in range(1, K):
    for j in range(i, K):
        for k in range(j, K):
            if i == j == k:
                ans += gcd(i, j, k) 
            elif i == j or j == k or k == i:
                ans += gcd(i, j, k) * 3
            else:  
                ans += gcd(i, j, k) * 6
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

k = INT()
ans = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            g = gcd(gcd(a, b), c)
            t = 6
            if a == b or b == c:
                t = 3
            if a == b == c:
                t = 1
            debug(g, t, a, b, c)
            ans += g * t
print(ans)

Solution (Python):
import math
from functools import reduce

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

k = int(input())
a = 0

for s in range(1,k+1):
    for t in range(1,k+1):
        for u in range(1,k+1):
            
            a += gcd(s,t,u)

print(a)

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '
        
        
    return ret


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations, combinations_with_replacement
from bisect import bisect_left, bisect_right  
from math import gcd


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


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


K = read_a_int()
print(ans[K])

Solution (Python):
import math

K = int(input())

total = 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):
            abc = math.gcd(ab, c)
            total += abc

print(str(total))

Solution (Python):
N = int(input())
import math
from functools import reduce

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

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

Solution (Python):
import math

k=int(input())

x=[0]*201

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

ans=0
for i in range(1,201):
    for j in range(1,k+1):
        w=math.gcd(i,j)
        ans+=w*x[i]
print(ans)

Solution (Python):
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
import sys

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


K = ii()

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)

Solution (Python):
import math

def solve():
    K = int(input())
    sum = 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):
                sum += math.gcd(ab, c)
                pass
    print(sum)


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
cnt = 0


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


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:
                cnt += gcd(i,j,k)
            elif i == j or j == k or k == i:
                cnt += gcd(i, j, k)*3
            else:
                cnt += gcd(i, j, k)*6
print(cnt)

Solution (Python):
import math

K = int(input())








print([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]
      [K])

Solution (Python):
import math
k=int(input())
l=range(1,k+1)
print(sum([math.gcd(x, math.gcd(y, z)) for x in l for y in l for z in l]))

Solution (Python):

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

k = int(input())
al = {}
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(i,j,l)

print(ans)

Solution (Python):
ans1=[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]
ans2=[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]

ans=ans1+ans2
print(ans[int(input())])

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

Solution (Python):
import math
N = int(input())
ans = 0
temp  = [ [-1] * (N + 1) for _ in range(N + 1)]
for i in range(1,N + 1):
    for j in range(i, N + 1):
        hoge = math.gcd(i,j)
        temp[i][j] =temp[j][i] = hoge


for i in range(1,N + 1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            hoge = temp[i][j]
            ans += temp[hoge][k]

print(ans)

Solution (Python):
import sys







import functools

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


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

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

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

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


if __name__ == "__main__":
    main()

Solution (Python):
import math


def main():
    n = int(input())
    l = [i for i in range(1, n + 1)]

    def gen(l):
        for i in l:
            for j in l:
                for k in l:
                    yield math.gcd(i, math.gcd(j, k))

    return sum(gen(l))


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

Solution (Python):

from collections import Counter


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


def resolve():
    k = int(input())
    l = [None] * k ** 2
    for i in range(k):
        for j in range(k):
            l[i * k + j] = gcd(i + 1, j + 1)
    c = Counter(l)
    ans = 0
    for key, v in c.items():
        for i in range(k):
            ans += gcd(i + 1, key) * v
    print(ans)


if __name__ == '__main__':
    resolve()

Solution (Python):
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)

Solution (Python):
K=int(input())
from math import gcd
s=0
G=[[0 for i in range(K)] for i in range(K)]
for i in range(0,K):
    for j in range(0,K):
        G[i][j]=gcd(i+1,j+1)
for a in range(0, K):
    for b in range(0,K):
        for c in range(0,K):
            s+=G[G[b][c]-1][a]
print(s)

Solution (Python):

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
k =  int(input())
ans=0
for i in range(k):
     for j in range(k):
          for h in range(k):
               ans += gcd(gcd(i+1,j+1),h+1)
print(ans)

Solution (Python):
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)