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

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):
            temp = math.gcd(a, b)
            ans += math.gcd(temp, c)

print(ans)

Solution (Python):
import math


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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


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


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


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


if __name__ == '__main__':
    main()

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


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


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

Solution (Python):
import math

K = int(input())

lists = []
for i in range(1, K + 1):
    for j in range(1, K + 1):
        mid = math.gcd(i, j)
        for k in range(1, K + 1):
            lists.append(math.gcd(mid, k))

print(sum(lists))

Solution (Python):
from math import gcd

def main():
    K=int(input())
    ans=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            tmp=gcd(a,b)
            for c in range(1,K+1):
                ans+=gcd(tmp,c)
    print(ans)

main()

Solution (Python):
import math
from itertools import combinations as com


k = int(input())
num = [i for i in range(1, k+1)]
cnt = sum(num)

for a,b in com(num, 2):
    cnt += 6 * math.gcd(a, b)

for a,b,c in com(num, 3):
    cnt += 6*math.gcd(c,math.gcd(a, b))

print(cnt)

Solution (Python):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
k = int(input())
s = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      s += gcd(a,b,c)
print(s)

Solution (Python):
import math

K = int(input())
count = 0

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

for k in range(1, K+1):
    for j in range(1, K+1):
        temp = A[k][j]
        for i in range(1, K+1):
            count += A[temp][i]
print(count)

Solution (Python):
from math import gcd
k = int(input())
s = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        t = gcd(x, y)
        if t == 1:
            s += k
            continue
        for z in range(1, k + 1):
            s += gcd(t, z)
print(s)

Solution (Python):

import sys
import math


def solve(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):
                if a != b and b != c:
                    ans += 6 * math.gcd(a,math.gcd(b,c))
                elif a != c:
                    ans += 3 * math.gcd(a,math.gcd(b,c))
                else:
                    ans += math.gcd(a,math.gcd(b,c))
    print(ans)


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

Solution (Python):
import math
def count(i,j,k):
    val= math.gcd(i,math.gcd(j,k))

    if i==j==k:
        return val
    else:
        if i==j or i==k or j==k:
            return 3*val
        else:
            return 6*val
n=int(input())+1
sum=0
for i in range(1,n):
    for j in range(i,n):
        for k in range(j,n):
            sum+=count(i,j,k)
print(sum)

Solution (Python):
import math

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

Solution (Python):
import math
from functools import reduce

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):
            cnt+=math.gcd(math.gcd(a,b),c)

print(cnt)

Solution (Python):
from sys import stdin, stdout
from math import gcd
def main():
    K = int(stdin.readline())
    sm = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                sm += gcd(i, gcd(j, k))
    stdout.write(str(sm)+"\n")
main()

Solution (Python):
import math
from functools import reduce

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,K+1):
        tmp = math.gcd(i,j)
        for k in range(1,K+1):
            if not i == j:
                SUM += math.gcd(tmp,k) * 2
            else:
                SUM += math.gcd(tmp,k)


print(SUM)

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

def main():
    ans = 0 
    K = int(input())
    for i in range(1, K+1):
        for j in range(1, K+1):
            if(i < j):
                gcd1 = GCD(j, i)
            else:
                gcd1 = GCD(i, j)
            for k in range(1, K+1):
                ans += GCD(gcd1, k)

    print(ans)



if __name__ == main():
    main()

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


def input():
    return sys.stdin.readline().strip()


def main():

    N = int(input())
    if N == 1:
        print(1)
    elif N == 2:
        print(9)
    else:
        A = list(combinations(range(1, N + 1), 2))
        B = list(combinations(range(1, N + 1), 3))
        ans = N * (N + 1) // 2
        for a in A:
            a = list(a)
            ans += gcd(a[0], a[1]) * 6
        for b in B:
            b = list(b)
            x = gcd(b[0], b[1])
            x = gcd(x, b[2])
            ans += x * 6
        print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
from fractions import gcd
k = int(input())
check = [[1 for _ in range(k+3)] for i in range(k+3)]
for i in range(1, k+2):
    for j in range(i, k+2):
        check[i][j] = gcd(i, j)

result = 0
for s in range(1, k+1):
    for t in range(1, k+1):
        for u in range(1, k+1): 
            n, m = sorted([s, t])
            x = check[n][m]
            x, y = sorted([x, u])
            result += check[x][y]
print(result)

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

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

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

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

import math
from functools import reduce

def gcd(*i):
    return reduce(math.gcd, i)
j = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            j += gcd(a,b,c)

print(j)

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def resolve():
    K = ir()
    def GCD(a, b):
        if b == 0:
            return a
        else:
            return GCD(b, a % b)
    ab = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            ab.append(GCD(i, j))
    A = Counter(ab)
    ans = 0
    for k in A.keys():
        for i in range(1, K+1):
            abc = GCD(k, i)
            ans += abc*A[k]
    print(ans)
resolve()

Solution (Python):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
K = int(input())
s = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      s+=gcd(a,b,c)
      
      
print(s)

Solution (Python):
import math


def main(K=None):
    if not K:
        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 += math.gcd(math.gcd(i, j), k)
    print(ans)
    return ans


if __name__ == "__main__":
    
    
    main()

Solution (Python):
import math

k=int(input())

count = 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):
            count += math.gcd(tmp, c)

print(count)

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

Solution (Python):
import sys,math
def input():
    return sys.stdin.readline()[:-1]
K = int(input())
ANS = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        elm = math.gcd(i,j)
        if elm==1:
            ANS += K
            continue
        for k in range(1,K+1):
            ANS += math.gcd(elm,k)
print(ANS)

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

import math

def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), 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 = ans + gcd(a,b,c)

print(ans)

Solution (Python):
from fractions import gcd

input = raw_input

k = int(input())
out = 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)
            out += g2

print(out)

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


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


ans = 0
d = [0] * (n+1)
for i in range(1,n+1):
  for j in range(1,n+1):
    d[gcd(i,j)] += 1

for i in range(1,n+1):
    for j in range(1,n+1):
        ans += gcd(i,j) * d[i]
print(ans)

Solution (Python):
def main():
    import math
    K = int(input())
    value = 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) :
                gcd_abc = math.gcd(gcd_ab,c)
                value = value + gcd_abc
    print(value)

if __name__ == '__main__':
    main()

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




n = int(input())




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

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):
k=int(input())
from math import gcd
s=0
for a in range(1,k+1):
	for b in range(1,k+1):
		for c in range(1,k+1):
			s+=gcd(gcd(a,b),c)
print(s)

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

l = [0 for i in range(k+1)]

for a in range(1, k+1):
    for b in range(1, k+1):
        l[math.gcd(a, b)-1] += 1

sum = 0
for i in range(1, k+1):
    for c in range(1, k+1):
        sum += l[i-1] * math.gcd(i, c)

print(sum)

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

ans=0
for i in range(1,k+1):
    for j in range(1,1+k):
        ans+=gcd(i,j)*l[i-1]
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 fractions import gcd
K = int(input())
res = 0
dp = {}
for a in range(K+1)[1:]:
  for b in range(K+1)[1:]:
    i = a
    j = b
    if b < a:
      i = b
      j = a
    if not i + j * (K+1) in dp:
      dp[i + j * (K+1)] = gcd(i, j)
    
    d = dp[i + j * (K+1)]

    for c in range(K+1)[1:]:
        

      s = c
      t = d
      if d < c:
        s = d
        t = c
      
      if not s + t * (K+1) in dp:
        dp[s + t * (K+1)] = gcd(s, t)
      res += dp[s + t * (K+1)]

print(res)

Solution (Python):
import math
from functools import reduce

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

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

print(cnt)

Solution (Python):
import math

k = int(input())

ans = 0

IJ = [[0 for j in range(k+1)] for i in range(k+1)]

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

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


print(ans)

Solution (Python):
import math


def gcd3(n1, n2, n3):
    return math.gcd(n1, math.gcd(n2, n3))


if __name__ == "__main__":
    k = int(input())
    res = dict()
    sum_ = 0

    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:
                    sum_ += gcd3(i, j, l)
                elif i != j and j != l and i != l:
                    sum_ += gcd3(i, j, l) * 6
                else:
                    sum_ += gcd3(i, j, l) * 3

    print(sum_)

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

k=0
for a in range(1,n+1):
    for b in range(1,n+1):
        a_b=math.gcd(a,b)
        for c in range(1,n+1):
            g=math.gcd(c,a_b)
            k=k+g

print(k)

Solution (Python):
import math

def ggcd(p,q,r):
    s = math.gcd(p,q)
    return math.gcd(r,s)

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

if __name__ == '__main__':
    main()

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

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

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):
            a = [i, j, k]
            ans += gcd_list(a)
            
print(ans)

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

def gcd(x, y):
    if x < y: x, y = y, x
    while y:
        n = x%y
        x = y
        y = n
    return x
    
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ret = gcd(i, j)
            ans += gcd(ret, k)

print(ans)

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

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

Solution (Python):
from math import gcd

def main():
    k = int(input())
    d = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                d += gcd(gcd(a, b), c) * [0, 1, 3, 6][len({a, b, c})]
    print(d)

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

print(ans)

Solution (Python):
import math
import functools as f

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

	

k = int(input())

s = 0

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

print(s)

Solution (Python):
import math
from functools import reduce

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

a = int(input())

ans = 0

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

print(ans)

Solution (Python):
import sys
import math
from functools import reduce
def input(): return sys.stdin.readline().rstrip()
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def main():
    k=int(input())
    sum=0
    for i in range(1,k-1):
        for j in range(i+1,k):
            for l in range(j+1,k+1):
                sum+=gcd(i,j,l)*6
    for i in range(1,k+1):
        for j in range(1,k+1):
            if i!=j:
                sum+=gcd(i,j,j)*3
    for i in range(1,k+1):
        sum+=gcd(i,i,i)
    print(sum)

if __name__=='__main__':
    main()

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

for i in range(n):
    num1 = i + 1
    for j in range(n - num1 + 1):
        num2 = j + num1
        gcd1 = math.gcd(num1, num2)
        for k in range(n - num2 + 1):
            num3 = k + num2
            gcd2 = math.gcd(gcd1, num3)
            if num1 == num2 and num2 == num3:
                ans += gcd2
            elif num1 == num2 or num2 == num3:
                ans += gcd2 * 3
            else:
                ans += gcd2 * 6

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

print(count)

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

Solution (Python):
import math


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


main()

Solution (Python):
import math

K = int(input())
r = 0

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

print(r)

Solution (Python):
import math
N = int(input())
ans=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):
            ans += math.gcd(p,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):
        tmp = math.gcd(a, b)
        for c in range(1, K+1):
            ans += math.gcd(tmp, c)

print(ans)

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

gcdmem = [[[0] * (K+1) for i in range(K+1)] for j in range(K+1)]

for a in range(1, K+1):
    for b in range(a, K+1):
        for c in range(b, K+1):
            if gcdmem[a][b][c] > 0:
                continue
            gcdab = math.gcd(a, b)
            gcdmem[a][b][c] = math.gcd(gcdab, c)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            s1, s2, s3 = sorted([a, b, c])
            ans += gcdmem[s1][s2][s3]

print(ans)

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

Solution (Python):
import math


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

Solution (Python):
import math

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

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

Solution (Python):
from math import gcd
def main():
    k = int(input())
    t = [0]*201
    for i in range(1, k+1):
        for j in range(1, k+1):
            t[gcd(i, j)] += 1
    ans = 0
    for i in range(1, 201):
        if t[i] > 0:
            for j in range(1, k+1):
                x = gcd(i, j)

                ans += x*t[i]
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):


from sys import stdin
import math
from functools import reduce

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

K = int(input())

counter = 0

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

print(counter)

Solution (Python):
from math import gcd

n = int(input())

sum = 0

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

print(sum)

Solution (Python):
from math import gcd

K = int(input())

s = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        d = gcd(a, b)
        if d == 1:
            s += K
            continue
        else:
            for c in range(1, K+1):
                s += gcd(d, c)

print(s)

Solution (Python):
from math import gcd
def main():
    K = int(input())
    r = 0
    l = {}
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                x = gcd(i,j)
                x = gcd(x,k)
                r += x
    return r
print(main())

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

Solution (Python):

import sys


def solve(K: int):
    s = 0
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            g1 = gcd(i, j)
            for k in range(1, K + 1):
                g2 = gcd(g1, k)
                s += g2
    print(s)
    return


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



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

Solution (Python):
import math

summation = 0

K = int(input())
for i in range(1, K + 1):
    for j in range(1, K + 1):
        gcd_i_j = math.gcd(i, j)
        for k in range(1, K + 1):
            gcd = math.gcd(gcd_i_j, k)
            summation += gcd

print(summation)

Solution (Python):
import math

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


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

Solution (Python):

import sys
from math import gcd

def solve(K: int):
    sum = 0
    
    for i1 in range(1,K+1):
        sum+=i1
        
    
    for i2 in range(1,K+1):
        for j2 in range(i2+1,K+1):
            sum+=6*gcd(i2,j2)
            
    
    for i in range(1,K+1):
        for j in range(i+1,K+1):
            for k in range(j+1,K+1):
                sum+=6*gcd(gcd(i,j),k)
    print(sum)



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

Solution (Python):
from math import gcd

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

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

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

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

Solution (Python):
import functools
import math

k = int(input())
cnt = 0


def gcd(a, b, c):
    return functools.reduce(math.gcd, [a, b, c])


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

print(cnt)

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

lsgcd=[]

for i in range(1,k+1):
    for j in range(1, k +1):
        lsgcd.append(math.gcd(i,j))


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

print(sum(ls2))

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(1, k+1):
    for j in range(i, k+1):
        for x in range(j, k+1):
            s = gcd(i,j,x)
            if i == j and j == x:
                pass
            elif i == j or i == x or j == x:
                s *= 3
            else:
                s *= 6
                
            ans += s
print(ans)

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

Solution (Python):

from math import gcd
k=int(input())
t=[]
for i in range(1,k+1):
    for j in range(1,k+1):
        t.append(gcd(i,j))
ans=[]
for tt in t:
    for i in range(1,k+1):
        ans.append(gcd(tt,i))
print(sum(ans))

Solution (Python):

import sys
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
from functools import reduce

def main():
    k = int(input())
    ans = 0
    ary = []
    for i in range(1,k+1):
        for j in range(1,k+1):
            ary.append(math.gcd(i,j))
    for i, aa in enumerate(ary):
        for j in range(1,k+1):
            ans += math.gcd(aa,j)
    print(ans)


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

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

if __name__=='__main__':
    main()