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

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

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

k = int(input())

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

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

print(ans)

Solution (Python):
import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    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)
    return


if __name__ == '__main__':
    main()

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

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

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

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

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

def gcd(x,y):
    if x<y:
        temp=x
        x=y
        y=temp
    if x%y==0:
        return y
    else:
        nx=y
        ny=x%y
        return gcd(nx,ny)
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)

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

def gcd(x,y):
    if x<y:
        temp=x
        x=y
        y=temp
    if x%y==0:
        return y
    else:
        nx=y
        ny=x%y
        return gcd(nx,ny)
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)

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

from math import gcd

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)

Solution (Python):
K = int(input())
ans = 0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

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

Solution (Python):
import math
ans=0

K=int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    num=math.gcd(i,j)
    for k in range(1,K+1):
      if num==1:
        ans+=1
      else:
        ans+=math.gcd(num,k)
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):
    ij_gcd = gcd(i,j)
    for l in range(1,k+1):
      ans += gcd(ij_gcd,l)

print(ans)

Solution (Python):
from math import gcd
from itertools import product
N = int(input())
print(sum(gcd(gcd(a,b),c) for a, b, c in product(range(1,N+1), repeat=3)))

Solution (Python):
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)
print(A[int(input())-1])

Solution (Python):
N = 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)
print(A[N-1])

Solution (Python):
def main():
    N = 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)
    print(A[N - 1])

if __name__ == '__main__':
    main()

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

print(A[N-1])

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

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

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

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

print(out)

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):
import math

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

Solution (Python):
from math import gcd
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, gcd(b, c))

print(sum)

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

sum = 0

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


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

Solution (Python):

"""
Created on Sat Jul 11 16:48:51 2020

@author: Aruto Hosaka
"""


import math
import collections

K = int(input())
ans = 0
g = []
for a in range(K):
  for b in range(K):
      g.append(math.gcd(a+1, b+1))
G = collections.Counter(g)

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

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

Solution (Python):

from math import gcd

K = int(input())

a = 0
for ai in range(1, K + 1):
  for bi in range(1, K + 1):
    gcd_ab = gcd(ai, bi)
    for ci in range(1, K + 1):
      a += gcd(gcd_ab, ci)

print(a)

Solution (Python):
from math import gcd
K = int(input())
ans = 0
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

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

ans += K*(K+1)//2

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

print(ans)

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

from math import gcd

s = 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):
      s += gcd(g, c)

print(s)

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

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

Solution (Python):
from math import gcd

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

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

Solution (Python):
import math
K = int(input())
gcd3 = 0
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            gcd3 += math.gcd(math.gcd(a,b),c)
gcd2 = 0
for a in range(1,K):
    for b in range(a+1,K+1):
        gcd2 += math.gcd(a,b)
ans = gcd3 * 6 + gcd2 * 6 + K*(K+1)//2
print(ans)

Solution (Python):
def gcd(x, y):
  if y==0: return x
  return gcd(y, x%y)
K = int(input())
res = 0
for a in range(1, K+1):
  for b in range(a, K+1):
    for c in range(b, K+1):
      if len(set([a, b, c]))==3: res += gcd(gcd(a, b), c) * 6
      elif len(set([a, b, c]))==2: res += gcd(gcd(a, b), c) * 3
      else: res += gcd(gcd(a, b), c)
print(res)

Solution (Python):
from math import gcd
from collections import Counter
k=int(input())
t=[]
for a in range(1,k+1):
  for b in range(1,k+1):
    t.append(gcd(a,b))      
t=Counter(t)
ans=0
for d,e in t.items():
  for c in range(1,k+1):
    g=gcd(c,d)
    ans+=g*e
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):
    for c in range(1,k+1):
      ans+=gcd(gcd(a,b),c)
print(ans)

Solution (Python):
import math
import sys

def main():
    n = int(sys.stdin.readline())

    total = 0

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

    print(total)

main()

Solution (Python):
import math
import sys

def main():
    n = int(sys.stdin.readline())

    total = 0

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

    print(total)

main()

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

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

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

Solution (Python):
from itertools import product

K = int(input())

def gcd_ab(a, b):
    
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd_ab(b, a%b)

def gcd(*args):
    r = args[0]
    for arg in args[1:]:
        r = gcd_ab(r, arg)
    return r

sum_num = 0
for a, b, c in product(range(1, K+1), repeat=3):
    sum_num += gcd(a, b, c)

print(sum_num)

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

Solution (Python):
k=int(input())
t=0
import math
for i in range(1,k+1):
    for j in range(1,k+1):
        s=math.gcd(i,j)
        for l in range(1,k+1):
            S=math.gcd(s,l)
            t+=S
print(t)

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

Solution (Python):
K = int(input())
ans = 0
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
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)

Solution (Python):

k = int(input())

gcd_cnt = {}

for n in range(k, 0, -1):
    div_all = (k // n) ** 3
    div_dup = 0
    for m in range(n * 2, k + 1, n):
        div_dup += gcd_cnt[m]
    gcd_cnt[n] = div_all - div_dup

ans = 0
for gcd in gcd_cnt.keys():
    ans += gcd * gcd_cnt[gcd]

print(ans)

Solution (Python):
import sys
from math import gcd
from itertools import combinations


def main():
    input = sys.stdin.buffer.readline
    k = int(input())
    dp = [1]*(k+1)
    for i in range(2, k+1):
        dp[i] = dp[i-1]+i
        for e in combinations(range(1, i), 2):
            dp[i] += 6*gcd(gcd(e[0], e[1]), i)
        for j in range(1, i):
            dp[i] += 6*gcd(i, j)
    print(dp[k])


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import math
from functools import reduce

n = int(input())
ans = 0

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

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

Solution (Python):
import math

K = int(input())

su = 0

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

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

Solution (Python):
import itertools, math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
K = int(input())
if K == 1:
    print(1)
    exit()
elif K ==2:
    print(9)
    exit()
l_2 = itertools.combinations(range(1, K + 1), 2)
l_3 = itertools.combinations(range(1, K + 1), 3)
sum = int(K * (K + 1) / 2)
for x in l_2:
    sum += math.gcd(x[0], x[1]) * 6
for x in l_3:
    sum += gcd(x[0], x[1], x[2]) * 6
print(sum)

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

sum=0

sum+=K*(K+1)//2

for i in range(1,K+1):
    for j in range(1,K+1):
        if j<=i:
            continue
        else:
            sum+=6*math.gcd(i,j)

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

print(sum)

Solution (Python):
import sys 
from functools import reduce
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def gcd(*numbers):
    return reduce(math.gcd, numbers)
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)

Solution (Python):
import math
from math import gcd

K = int(input())
result = 0

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

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

if K >= 3:
    for i in range(1, K-1):
        for j in range(i+1, K):
            for k in range(j+1, K+1):
                result += gcd(gcd(i,j),k) * 6

print(result)

Solution (Python):
import sys
input = sys.stdin.readline
from math import gcd

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

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

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

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

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

Solution (Python):
import math
from functools import reduce

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

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

print(sum)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')


from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations




from math import gcd
def solve():
    K = II()

    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 = ans + gcd(g, c)
    print(ans)
if __name__ == '__main__':
    solve()

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

print(ans)

Solution (Python):
n=int(input())
from math import gcd
import itertools
lst=[i for i in range(1,n+1)]
kumi=list(itertools.combinations_with_replacement(lst,3))
ans=0
for i in range(len(kumi)):
    a=kumi[i][0]
    b=kumi[i][1]
    c=kumi[i][2]
    g=gcd(gcd(a,b),c)
    if a==b==c:
        ans+=g
    elif a==b or a==c or b==c:
        ans+=3*g
    else:
        ans+=6*g

print(ans)

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

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

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


sum_gcd = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for n in range(1,k+1):
      sum_gcd += gcd3(i,j,n)
print(sum_gcd)

Solution (Python):
import math

k = int(input())

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

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())

def gcd(a, b):
    if a == 0 or b == 0:
        return max(a,b)
    x, y = min(a,b), max(a,b)
    return gcd(x,y%x )

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)

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

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

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

Solution (Python):
import math
k=int(input())
ans= 0
for s in range(1,k+1):
    for t in range(1,k+1):
        if math.gcd(s,t) == 1:
            ans=ans+k
        else:
            for u in range(1,k+1):
                ans= ans + math.gcd(math.gcd(s,t),u)
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):
    v = gcd(i,j)
    for m in range(1,k+1):
      ans += gcd(v,m)
print(ans)

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

Solution (Python):
import math
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):
            gcd_1 = math.gcd(i,j)
            sum = sum + math.gcd(gcd_1,k)
print(sum)

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

ans=0
for a in range(1,n+1):
  for b in range(1,n+1):
    d=math.gcd(a,b)
    if d==1:
      ans+=n
      continue
    if d==2:
      ans+=n//2*3+n%2
      continue
    if d==3:
      ans+=n//3*5+n%3
      continue
    if d==5:
      ans+=n//5*9+n%5
      continue
    for c in range(1,n+1):
      ans += math.gcd(c,d)

print(ans)

Solution (Python):
import numpy as np
n=int(input())

ans=0
for a in range(1,n+1):
  for b in range(1,n+1):
    d=np.gcd(a,b)
    if d==1:
      ans+=n
      continue
    if d==2:
      ans+=n//2*3+n%2
      continue
    if d==3:
      ans+=n//3*5+n%3
      continue
    if d==5:
      ans+=n//5*9+n%5
      continue
    for c in range(1,n+1):
      ans += np.gcd(c,d)

print(ans)

Solution (Python):



import math

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

Solution (Python):

from functools import reduce
from itertools import combinations
from math import gcd

K = int(input())

sum = K * (K + 1) // 2

for i in combinations(range(K + 1), 3):
    sum += 6 * reduce(gcd, i)

print(sum)

Solution (Python):

from functools import reduce
from itertools import combinations
from math import gcd

K = int(input())

sum = K * (K + 1) // 2

for i in combinations(range(1, K + 1), 2):
    sum += 6 * reduce(gcd, i)

for i in combinations(range(1, K + 1), 3):
    sum += 6 * reduce(gcd, i)

print(sum)

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)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

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


main()