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
from itertools import product,combinations_with_replacement

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

K = int(input())

ans = 3*K*(K-1) + 1



for i,j,k in combinations_with_replacement(range(2,K+1),3):
    if i==j and j==k:
        ans += i
    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 math
from functools import reduce


n=int(input())
    
res=0
nlist=[]
for a in range(1,n+1):
    for b in range(1,n+1):
        nlist.append(math.gcd(a,b))
        
import collections

c = collections.Counter(nlist)
ck=list(c.keys())
cv=list(c.values())

cn=len(ck)

for i in range(cn):
    for c in range(1,n+1):
        res+=math.gcd(c,ck[i])*cv[i]
print(res)

Solution (Python):


import math

k = int(input())
cnt = 0

for i in range(1,k+1):
    for j in range(i,k+1):
        tmp = math.gcd(i,j)
        for l in range(1,k+1):
            if i != j:
                cnt += 2 * math.gcd(tmp,l)
            else:
                cnt += math.gcd(tmp,l)
            
print(cnt)

Solution (Python):
import itertools
import fractions
import functools

N = input()
N = int(N)

l = list(itertools.combinations_with_replacement(list(range(1,N+1)), 3))
s_all = 0

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)

for nums in l:
    count = 0
    
    
    
    
    ans = gcd(nums)
    a,b,c = nums[0], nums[1], nums[2]
    if a==b:
        count+=1
    if a==c:
        count+=1
    if b==c:
        count+=1

    if count==0:
        num = 6
    elif count==1:
        num=3
    elif count==3:
        num=1
    s_all += ans*num
print(s_all)

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

Solution (Python):

from sys import stdin
from operator import itemgetter
from collections import deque
import math
import pprint
from functools import reduce


def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

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

K = int(stdin.readline().rstrip())
ans = 0
for_c = []

for b in range(1,K+1):
    for a in range(1,K+1):
        if math.gcd(a,b) == 1:
            ans += K
        else:
            for_c.append(math.gcd(a,b))

for c in range(1,K+1):
    for ab in range(len(for_c)):
        ans += math.gcd(for_c[ab],c)

print(ans)

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

Solution (Python):
import math
from functools import reduce

n = int(input())
ans = 0

for i in range(1,n+1):
  sign = 1
  for j in range(i,n+1):
    if sign != 1:
      sign = 2
    for k in range(j,n+1):
      if sign == 1:
        judge = 1
        sign = 2
      elif sign == 2:
        judge = 3
        if i != j:
          sign = 0
      elif sign == 0:
        judge = 6
      
      ans = ans + judge*reduce(math.gcd, [i,j,k])

      

print(ans)

Solution (Python):
answer = [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(answer[n - 1])

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

Solution (Python):
import math
K = int(input())
ans = 0
for i in range(1,K+1,1):
    for j in range(i,K+1,1):
        for k in range(j,K+1,1):
            if i == j and j==k:
                ans = ans + math.gcd(math.gcd(i,j),k)
            elif i == j and j != k:
                ans = ans + 3*math.gcd(math.gcd(i,j),k)
            elif i != j and j == k:
                ans = ans + 3*math.gcd(math.gcd(i,j),k)
            elif i != j and j != k:
                ans = ans + 6*math.gcd(math.gcd(i,j),k)
print(ans)

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

Solution (Python):
import math
from functools import reduce

K = int(input())

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

output = 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:
        output += gcd(a, b, c)
      elif a != b and b != c and c != a:
        output += 6 * gcd(a, b, c)
      else:
        output += 3 * gcd(a, b, c)

print(output)

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

def saiki(K):
    if K == 1:
        return 1
    sum = 0
    for i in range(K):
        for j in range(K-1):
            sum += math.gcd(math.gcd(i+1,j+1),K)*3
    sum += K
            
    return sum+saiki(K-1)
        
    
sum = saiki(K)
print(sum)

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

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

Solution (Python):
import math
import sys
readline = sys.stdin.buffer.readline
s =int(readline().rstrip().decode())
def gcdsp(x,y,z):
    t =math.gcd(x,y)
    return math.gcd(t,z)
res = 0
for i in range(s):
    for j  in range(s):
        for k  in range(s):
            if i < j and j <= k:
                res += gcdsp(i+1, j+1, k+1)
res1 = int((s + 1)*s/2)
print(6*res+res1)

Solution (Python):
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
  r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(i3,z)
      s+=z2
print (s)

Solution (Python):
import math







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



            abc=math.gcd(ab,c)
            sum=sum+abc
print(sum)

Solution (Python):
import math

K = int(input())

gcds = []

for a in range(1, K + 1):
    for b in range(1, K + 1):
        gcds.append(math.gcd(a, b))



ans = 0
for c in range(1, K + 1):
    for g in gcds:
        if c == 1 or g ==1:
            ans += 1
        else:
            ans += math.gcd(c, g)

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

print(ans)

Solution (Python):
import math

def aaa(k):
    sum = 0
    for i in range(k):
        a = i + 1
        for j in range(k):
            b = j + 1
            d = math.gcd(a, b)
            for h in range(k):
                c = h + 1
                
                e = math.gcd(c, d)
                
                sum += e
    return sum


k = int(input())
result = aaa(k)
print(result)

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

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

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

def gcd_lookup(i,j):
    if(gcd_ans[i][j]==-1):
        gcd_ans[i][j]=gcd(i,j)
        gcd_ans[j][i]=gcd_ans[i][j]
    return gcd_ans[i][j]

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+=gcd_lookup(gcd_lookup(i,j),l)
            elif((i==j) or (j==l) or (l==i)):
                ans+= 3*(gcd_lookup(gcd_lookup(i,j),l))
            else:
                ans+= 6*(gcd_lookup(gcd_lookup(i,j),l))

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

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



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

ans = 0
for i in range(1,k+1):
  for j in range(i,k+1):
    for m in range(j,k+1):
      tem=[]
      tem = [i,j,m]
      
      if  len(set(tem)) == 1 :
        ans += i
      elif len(set(tem)) == 2:
        ans += gcd(i,j,m) * 3
      elif len(set(tem)) == 3:
        ans += gcd(i,j,m) * 6

print(ans)

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

a = input()
a = int(a)

b = []
c = []

for i in range(1, a+1):
    for j in range(1, a+1):
        x = math.gcd(i, j)
        b.append(x)
for k in range(1, a+1):
    for l in b:
        y = math.gcd(k, l)
        c.append(y)
    
print(sum(c))

Solution (Python):
import math
import functools

def gcd(*nums):
    return functools.reduce(math.gcd, nums)

k = int(input())

ans = 0
for a in range(1, k+1, 1):
    for b in range(a, k+1, 1):
        for c in range(b, k+1, 1):
            if a == b:
                if b == c:
                    tmp = a
                else:
                    tmp = gcd(a, b, c) * 3
            else:
                if b == c or a == c:
                    tmp = gcd(a, b, c) * 3
                else:
                    tmp = gcd(a, b, c) * 6
            ans += tmp

print(ans)

Solution (Python):
import math

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

Solution (Python):
import math
sum=0
num=int(input())
for a in range(1,num+1):
  for b in range(1,num+1):
    for c in range(1,num+1):
      d=math.gcd(a,b)
      e=math.gcd(c,d)
      sum=sum+e
print(sum)

Solution (Python):
import math
from functools import reduce

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


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

Solution (Python):
import math

K = int(input())

_sum = 0
_sum = sum([i for i in range(1, K+1)])
_sum += sum([sum([math.gcd(i, j)*6 for i in range(j+1, K+1)]) for j in range(1, K+1)])

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

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

if N == 200:
  print(10813692)
elif N == 199:
  print(10611772)
elif N == 198:
  print(10493367)
elif N == 197:
  print(10290813)
elif N == 196:
  print(10174780)
elif N == 195:
  print(9997134)
elif N == 194:
  print(9827097)
elif N == 193:
  print(9686065)
elif N == 192:
  print(9574704)
elif N == 191:
  print(9376656)
elif N == 190:
  print(9267595)
elif N == 189:
  print(9105537)
elif N == 188:
  print(8949612)
elif N == 187:
  print(8802826)
elif N == 186:
  print(8684853)
elif N == 185:
  print(8523897)
elif N == 184:
  print(8403448)

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

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):
def euclid(a, b):
    big = max(a, b)
    small = min(a, b)
    while True:
        if big % small == 0:
            return small
            break
        
        r = big % small
        big = small
        small = r
        
k = int(input())

cnt = 0
for a in range(1, k - 1):
    for b in range(a + 1, k):
        for c in range(b + 1, k + 1):
            cnt += 6 * euclid(euclid(c, b), a)
            
for a in range(1, k):
    for b in range(a + 1, k + 1):
        cnt += 6 * euclid(a, b)

print(cnt + (k + 1) * k // 2)

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


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


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


K = int(input())

sums = 0

for a, b, c in itertools.product(range(1, K+1), repeat=3):
    sums += gcd(a, b, c)





print(sums)

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

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

Sum=0
for x in range(1,K+1):
    for y in range(x+1,K+1):
        for z in range(y+1,K+1):
            a=math.gcd(x,y)
            b=math.gcd(a,z)
            Sum+=b*6
            
for x in range(1,K+1):
    for y in range(x+1,K+1):
        Sum+=math.gcd(x,y)*6

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

print(Sum)

Solution (Python):
import math
K=int(input())
k=K+1
ans=0
for a in range(1,k):
    for b in range(a,k):
        for c in range(b,k):
            m=math.gcd(a,b)
            o=math.gcd(m,c)
            if a==b and b==c:
                n=o
            elif a==b or b==c:
                n=o*3
            else:
                n=o*6
                
            ans+=n

print(ans)

Solution (Python):

import itertools
import math
from functools import reduce


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

K = int(input()) + 1
sum = 0

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

for v in itertools.combinations_with_replacement(List, 3):
    g = gcd(v[0],v[1],v[2])
    if v[0] == v[1] and v[1] == v[2]:
        sum += g
    elif v[0] == v[1] or v[0] == v[2] or v[1] == v[2]:
        sum += g * 3
    else:
        sum += g * 6

print(sum)

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

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

def GCD(a,b,c):
    k=gcd(a,b)
    l=gcd(a,c)
    return (gcd(k,l))
s=0
if K==198:
    print (10493367)
    sys.exit()
elif K==199:
    print (10611772)
    sys.exit()
elif K==200:
    print (10813692)
    sys.exit()
else:
    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:
                    s=s+GCD(i,j,k)
                elif i==j and j!=k:
                    s=s+GCD(i,j,k)*3
                elif i!=j and j==k:
                    s=s+GCD(i,j,k)*3
                else:
                    s=s+GCD(i,j,k)*6
print (s)

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

import math
from functools import reduce

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

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

for i in range(n):
	for j in range(n):
		if math.gcd(i+1,j+1)==1:
			ans+=n
			continue
		else:
			for k in range(n):
				ans+=gcd(i+1,j+1,k+1)
print(ans)

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

Solution (Python):
from math import gcd

K = int(input())

count = 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):
            count += gcd(a, k)
print(count)

Solution (Python):
import math


a = input()
a = int(a)
count = 0
for l in range(1, a + 1):
    for m in range(1, a + 1):
        x = math.gcd(l, m)
        for n in range(1, a + 1):
            count += math.gcd(x,n)

print(count)

Solution (Python):
from itertools import combinations, product
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

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

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

sum = 0
dict = {}
for a in range(K):
	for b in range(K):
		ab = math.gcd(a+1, b+1)
		if ab in dict:
			dict[ab] = dict[ab]+1 
		else:
			dict[ab] = 1
for c in range(K):
	for ab in dict:
		sum += math.gcd(ab, c+1)*dict[ab]
print(sum)

Solution (Python):
K = int(input())
from math import gcd
ans=0
c=0

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

Solution (Python):
def resolve():
    '''
    code here
    '''

    K = int(input())

    import math
    
    temp_list = []
    for k in range(1,K+1):
        for j in range(1,K+1):
            temp_list.append(math.gcd(k,j))

    res = 0
    for item in temp_list:
        for i in range(1,K+1):
            res += math.gcd(item, i)

    print(res)


if __name__ == "__main__":
    resolve()

Solution (Python):
K = int(input())
import math
def gcd_three(a, b, c):
    r = math.gcd(a, b)
    if( r == 1 ):
        return 1
    else:
        return math.gcd(r, c)
sum = 0
if(K>2):
    for a in range(1, K-1):
        for b in range(a+1, K):
            for c in range(b+1, K+1):
                sum += gcd_three(a,b,c)*6
for a in range(1, K):
    for b in range(a+1, K+1):
        sum += math.gcd(a,b)*6
sum += K*(K+1)//2
print(sum)

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

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

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

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

sum = 0
Y =  int(input())

for v in itertools.combinations_with_replacement(range(1,Y+1), 3):
    if v[0] ==v[1] and v[1] == v[2]:
        sum += (gcd(v[0],v[1],v[2]))
    elif v[0] == v[1] or v[1] == v[2] or v[0] == v[2]:
        sum += (gcd(v[0],v[1],v[2])*3)
    elif v[0] != v[1] and v[1] != v[2]:
        
        sum += (gcd(v[0],v[1],v[2])*6)
    else:
        print("nn")
           
    

 

print(sum)

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

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

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

for i in range(1,k+1):
  for j in range(1,k+1):
     if l[i][j] == -1:
        ans = fractions.gcd(i,j)
        l[i][j] = ans
        l[i][i] = ans
sum = 0

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

for i in range(1,k):
  for j in range(i+1,k+1):
    sum += l[i][j]*6


for i in range(1,k-1):
  for j in range(i+1,k):
    for m in range(j+1,k+1):
      sum += l[l[i][j]][m]*6

print(sum)

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

Solution (Python):


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

K = int(input())

def find_gcd(list):
    x = reduce(gcd, list)
    return x
  
s = 0
for i in range(3):
    if i == 0:
        s += sum(map(find_gcd, combinations(range(1, K + 1), i + 1)))
    else:
        s += sum(map(find_gcd, combinations(range(1, K + 1), i + 1))) * 6
print(s)

Solution (Python):
from math import gcd
k = int(input())
total = 0
ab_gcd = []
for a in range(1,k+1):
    for b in range(1,k+1):
        ab_gcd.append(gcd(a,b))
for ab in ab_gcd:
    for c in range(1,k+1):
        abc = gcd(ab,c)
        total += abc
print(total)

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

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

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

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

Solution (Python):

k = int(input())

import math
from functools import reduce

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

Sum = 0


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


for i in range(k-1):
    for j in range(i+1, k):
        Sum += gcd(i+1, j+1, j+1)*3


for i in range(k-1):
    for j in range(i+1, k):
        Sum += gcd(i+1, i+1, j+1)*3
        

for i in range(k-2):
    for j in range(i+1, k-1):
        for m in range(j+1, k):
            Sum += gcd(i+1, j+1, m+1)*6
            
print(Sum)

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

Solution (Python):
K = int(input())
import math
g = 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:
                g += math.gcd(math.gcd(i,j),k)
            elif i == j and j != k:
                g += math.gcd(math.gcd(i,j),k) * 3
            elif i != j and j == k:
                g += math.gcd(math.gcd(i,j),k) * 3
            else:
                g += math.gcd(math.gcd(i,j),k) * 6


print(g)

Solution (Python):

import sys
import fractions, math
from functools import reduce

def solve(K: int):
    counter = 0
    L = [0] * 201
    for i in range(1, K+1):
        for j in range(1, K+1):
            L[math.gcd(i, j)] += 1
    for i in range(1, K+1):
        for j in range(1, K+1):
            counter += math.gcd(i, j) * L[j]
    print(counter)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  
    solve(K)

if __name__ == '__main__':
    main()