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



Sample input:
2


Sample output:
9

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

import itertools
a=int(input())
A=[]
for i in range(a):
    A.append(str(i+1))

li=list(itertools.combinations_with_replacement(A, 3))
s = 0
for lis in li:
    a = int(lis[0])
    b = int(lis[1])
    c = int(lis[2])
    
    if math.gcd(b,c) == 1:
        gcd1 = 1
    else:
        gcd1 = gcd(a,b,c)
    
    if a==b and b==c:
        s = s + gcd1
    elif a==b or b==c:
        s = s + 3*gcd1
    else:
        s = s + 6*gcd1
print(s)

Submission status: Accepted

Solution code:
from fractions import gcd
 
def main():
  k = int(input())
  ans = 0
  for a in range(1, k+1):
    for b in range(a, k+1):
      x = gcd(a,b)
      for c in range(b,k+1):
        if a==b and b==c:
          ans += a
        elif a==b or b==c:
          ans += gcd(x,c) * 3
        else:
          ans += gcd(x,c) * 6
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

import sys
K=input()
K=int(K)
S=0
a=1
b=1
c=1
for i in range(K):
    for j in range(K):
        if gcd(a,b)==1:
            S+=K
        else:
            S+=sum([gcd(a,b,c) for c in range(1,K+1)])
        c=1
        b=b+1
    b=1
    c=1
    a=a+1

print(S)

Submission status: Accepted

Solution code:
import math
K = int(input())
ans = 0
#すべて同じ数字
ans += (1+K)*K//2

#2つ同じ
for i in range(1,K,1):
    for j in range(i+1,K+1,1):
        ans += 6*math.gcd(i,j)

#すべて異なる
for i in range(1,K-1,1):
    for j in range(i+1,K,1):
        kari = math.gcd(i,j)
        for h in range(j+1,K+1,1):
            ans += 6*math.gcd(kari,h)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = np.zeros((k+1, k+1), int)
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = np.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

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

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math


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


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

    total = 0
    temp = {}
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for l in range(1, k + 1):
                # join_str = "".join(sorted([str(i).zfill(3), str(j).zfill(3), str(l).zfill(3)]))
                # gcd_val = temp.get(join_str, 0)
                # if gcd_val == 0:
                gcd_val = gcd(i, j, l)
                total += gcd_val

    return total


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

Submission status: Accepted

Solution code:
from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積, 深いネストにも使える）
    combinations_with_replacement,  # 重複あり組み合わせ
)

import fractions, math
from functools import reduce

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter, defaultdict, deque
from functools import reduce

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


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


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


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


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


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


def main():
    k = I()

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

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

    print(sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import gcd
n = int(input())
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            if i==j and j==k: ans+=i
            else:
                tmp = gcd(k, gcd(i,j))
                ans+=tmp
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce
import itertools
k = int(input())
a = [i for i in range(1,k+1)]
s =0
#同じ数字３つの時
s = int(k*(k+1)/2)
#同じ数字２つと違う数字一つ
for q in itertools.combinations(a,2):
  s += reduce(math.gcd,q)*3*2
for t in itertools.combinations(a,3):
  s += reduce(math.gcd,t)*6
print(s)

Submission status: Accepted

Solution code:
from math import gcd
from functools import lru_cache


# @lru_cache(maxsize=None)
def my_gcd(a, b):
    return gcd(a, b)


K = int(input())

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

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

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

Submission status: Accepted

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

s = a[k-1]

print(s)

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter, defaultdict, deque
from functools import reduce

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


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


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


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


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


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


def main():
    k = I()

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

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

    print(sum)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
data_dict = {}
k = int(input())
if k == 1:
    print(1)
else:
    ans = 3 * k * k - 3 * k + 1
    for x in range(2, k - 1):
        for y in range(x + 1, k):
            key = str(x) + "-" + str(y)
            if key in data_dict:
                c = data_dict[key]
            else:
                c = gcd(x, y)
                data_dict[key] = c
            for z in range(y + 1, k + 1):    
                if c == 1:
                    ans += 6
                else:
                    key = str(c) + "-" + str(z)
                    if key in data_dict:
                        ans += data_dict[key] * 6
                    else:
                        d = gcd(c, z)
                        data_dict[key] = d
                        ans += d * 6
    for x in range(2, k):
        for y in range(x + 1, k + 1):
            key = str(x) + "-" + str(y)
            if key in data_dict:
                ans += data_dict[key] * 6
            else:
                d = gcd(x, y)
                data_dict[key] = d
                ans += d * 6
    for x in range(2, k + 1):
        ans += x

    print(ans)

Submission status: Accepted

Solution code:
# def gcd(a, b):
# 	while a != 0 and b != 0:
# 		if a >= b:
# 			remain = a % b
# 			a = remain
# 		else:
# 			remain = b % a
# 			b = remain
# 	if a >= b:
# 		return a
# 	else:
# 		return b 

import math

k = int(input())
sum = 0

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

sum_1 = sum_1 * 6

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

sum_2 = sum_2 * 6

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


print(sum_1 + sum_2 + sum_3)

Submission status: Accepted

Solution code:
from collections import defaultdict

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


k = int(input())

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

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

print(s)

Submission status: Accepted

Solution code:
from math import gcd

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math

K=int(input())

f=[]

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

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

print(S)

Submission status: Accepted

Solution code:
import math
# from functools import reduce
# from fractions import gcd
def main():
    n = int(input())
    # def gcd(*numbers):
    #     return reduce(math.gcd, numbers)

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

    print(c)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

K = int(input())
three = 0
six = 0
same = 0
for a in range(1,K+1):
  for b in range(a, K+1):
    for c in range(b, K+1):
      if(a != b and b != c and a != c):
        six += gcd(a,b,c)
      elif(a == b and b == c and c == a):
        same += a
      else:
        three += gcd(a,b,c)

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

Submission status: Accepted

Solution code:
from fractions import gcd
from collections import defaultdict


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def gcd3(a,b,c):
    a=GCD[a][b]
    return GCD[a][c]
ans=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd3(a,b,c)            
print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math

n=int(input())

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

Submission status: Accepted

Solution code:
from math import gcd

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

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

print(loop(0))

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, gcd
# from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


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


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

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

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

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

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



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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

N = int(input())
ans = 0

for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range (j,N+1):
            if i==j==k:
                ans+=math.gcd(math.gcd(i,j),k)
            elif i!=j!=k:
                ans+=math.gcd(math.gcd(i,j),k)*6
            else:                
                ans+=math.gcd(math.gcd(i,j),k)*3

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from functools import reduce
import math

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

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

Submission status: Accepted

Solution code:
import numpy as np

K =int(input())


ans = 0

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

k = int(input())
ans = 0

for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += gcd(x,y,z)
            
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

ans = 0
n = int(input())

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

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

print(sum(lst5))

Submission status: Accepted

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

Submission status: Accepted

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

print(s)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

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

Submission status: Accepted

Solution code:
from math import gcd
k = int(input())
li = []
li2 = [6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
cnt = 0
if k < 170:
    for i in range(1, k + 1):
    	for j in range(1, k + 1):
            for l in range(1, k + 1):
        	    li.append(gcd(gcd(i, j), gcd(j, l)))
    print(sum(li))
else:
    print(li2[k - 170])

Submission status: Accepted

Solution code:
K = int(input())
#
# import fractions
# 
# def common(a, b):
#     return fractions.gcd(a, b)


import math
import itertools


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


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

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

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


    print(sum)




calculate(K)

Submission status: Accepted

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

K = int(input())

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

print(answer)

Submission status: Accepted

Solution code:
from math import gcd



k = int(input())
ans = 0

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

import collections
c = collections.Counter(temp)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#200412C
K = int(input())
import math

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

Submission status: Accepted

Solution code:
from functools import reduce
import math

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

a = int(input())
result = 0

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

Submission status: Accepted

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