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: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if not b:
        return a
    else:
        return gcd(b, a%b)

n = int(input())

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from functools import reduce


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


k = int(input())
ans = 0
for abc in itertools.product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
def gcd(*nums):
    return reduce(math.gcd, nums)

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)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

import math
result=0
for i in range(1,n+1):
    for ii in range(1,n+1):
        for iii in range(1,n+1):
            temp=math.gcd(i,ii)
            result+=math.gcd(temp,iii)
print(result)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from math import gcd

k = int(input())

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
t = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ab = math.gcd(a, b)
            d = math.gcd(ab, c)
            t += d

print(t)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

k = int(input())
d = {}

ans = 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, c) in d:
                ans += d[(a, b, c)]
            else:
                d[(a, b, c)] = gcd(a, gcd(b, c))
                ans += d[(a, b, c)]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
# import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]


import math
from functools import reduce


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


K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd_list([a, b, c])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans+=gcd(i,gcd(j,l))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

import math
from functools import reduce
def gcd(numbers):
    return reduce(math.gcd,numbers)

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)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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):
        for c in range(1, n + 1):
            ret += gcdArr((a, b, c))
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
if __name__ == '__main__':
    a = int(input())

    count = 0

    for i in range(1,a+1):
        for j in range(1, a + 1):
            for k in range(1, a + 1):
                count += gcd(i,j,k)

    print(count)

Submission status: Time Limit Exceeded

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

K = int(input())

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            s = gcd(j, k)
            t = gcd(i, s)
            tot += t
print(tot)

Submission status: Time Limit Exceeded

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

# 二分探索
"""import bisect # 二分探索
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""

# 円周率 pi
"""import math
pi_ = math.pi"""

# エラトステネスの篩
"""def Erato(n):
    prime = []
    is_prime = [True] * (n+1)
    p = 0
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
      if is_prime[i] == True:
        prime.append(i)
        p += 1
        for j in range(2 * i,n+1,i):
          is_prime[j] = False
    return p"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def main():
  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)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
cnt = 0

for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            tmp = math.gcd(l,m)
            cnt += math.gcd(tmp,n)
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
from functools import reduce
def gcd_list(xs):
    return reduce(gcd, xs)

n = int(input())
a = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            a += gcd_list([i,j,k])
print(a)

Submission status: Time Limit Exceeded

Solution code:
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):
            d = math.gcd(i,j)
            ans += math.gcd(d, l)
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from math import gcd

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

input = stdin.readline

n = int(input())
res = 0

for x in range(1, n + 1):
    for y in range(1, n + 1):
        for z in range(1, n + 1):
            res += f(x, y, z)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
ans = 0
K = int(input())
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            d = gcd(a,b)
            e = gcd(d,c)
            ans += e
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

ans = 0

import math

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x,y):
    #print(x,y)
    if x > y:
        x,y = y,x
    while True:
        y = y % x
        if y == 0:
            #print(x)
            return x
        x,y = y,x
        
k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans += gcd(gcd(i,j),l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')
 
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

K = iin()

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd

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


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    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)
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

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

print(s)

Submission status: Time Limit Exceeded

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

def GCD(a,b):
    if not b:
        return a
    return GCD(b,a%b)
ans=0
for x in range(1,K+1):
    for y in range(1,K+1):
        for z in range(1,K+1):
            ans+=reduce(GCD,[x,y,z])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

k = ni()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
if __name__ == '__main__':
    k = int(input())
    ans = 0
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            for y in range(1, k + 1):
                ans += math.gcd(i, math.gcd(j, y))

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
  while(x % y != 0 and y % x != 0):
    if(x > y):
      x = x % y
    else:
      y = y % x
  if(x > y):
    return y
  else:
    return x

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
K = int(input())
ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for h in range(1,K+1):
      x = gcd(i,j)
      y = gcd(x,h)
      ans += y
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    """
    return gcd of a,b
    ユークリッド
    """
    while b:
        a, b = b, a % b
    return a


def list_gcd(l):
    """
    l: list
    l のgcd を返す
    """
    return reduce(gcd, l)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import *
from heapq import *
from itertools import *
from fractions import gcd

from decimal import *
import copy
from bisect import *
import time
import sys
import math
input=lambda :sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
K=int(input())
#A,B=map(int,input().split())
#A=list(map(int,input().split()))
z=0
for a in range(1,K+1):
    for b in range(1,K+1):
        d=gcd(a,b)
        for c in range(1,K+1):
            z+=gcd(c,d)
print(z)

Submission status: Time Limit Exceeded

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
total = 0

def gcd2(a,b): #互除法
  while True:
    mod = a % b
    if mod == 0:
      return b
    a = b
    b = mod

memo = {}
def gcd(a,b,c):
  return gcd2(gcd2(a,b),c)
#  a,b,c = sorted([a,b,c])
#  if (a,b,c) not in memo:
#    val = gcd2(gcd2(a,b), c)
#    memo[(a,b,c)] = val
#    return val
#  return memo[(a,b,c)]

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      g = gcd(a, b, c)
#      print(a,b,c, g)
      total += g

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
K=int(input())
ans=0
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(g,c)
print(ans)

Submission status: Accepted

Solution code:
import math
K =  int(input())
ans = []
bc = [math.gcd(b, c) for b in range(1, K+1) for c in range(1, K+1)]
for a in range(1, K+1):
    for i in bc:
        x = math.gcd(a, i)
        ans.append(x)
print(sum(ans))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from math import gcd

K = int(input())

one = 0
two = 0
three = 0
for i in range(1,K-1):
    for j in range(i+1,K):
        for k in range(j+1,K+1):
            d = gcd(i,j)
            d = gcd(d,k)
            three += d

for i in range(1,K):
    for j in range(i+1,K+1):
        d = gcd(i,j)
        two += d
for i in range(1,K+1):
    one += i

ans = one + two * 6 + three * 6
print(ans)

Submission status: Accepted

Solution code:
import math

K = int(input())

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

result = 0
for i in range(1, K+1):
    for t in g:
        result += math.gcd(i, t)

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
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:
import itertools as itt
import math

k = int(input())

ans = 0
for i in itt.combinations_with_replacement(range(1, k+1), 3):
    if i[0] == i[1] and i[0] != i[2]:
        ans += 3 * math.gcd(math.gcd(i[0], i[1]), i[2])
    elif i[1] == i[2] and i[1] != i[0]:
        ans += 3 * math.gcd(math.gcd(i[0], i[1]), i[2])
    elif i[0] == i[1] and i[0] == i[2]:
        ans += math.gcd(math.gcd(i[0], i[1]), i[2])
    else:
        ans += 6 * math.gcd(math.gcd(i[0], i[1]), i[2])

print(ans)

Submission status: Accepted

Solution code:
from math import gcd

k = int(input())

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

print(ans)

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

print(ans)

Submission status: Accepted

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

K=int(input())

#余裕でTLE?

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

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

Submission status: Accepted

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

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
k = int(input())
sum = 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):
            sum += gcd(x, c)

print(sum)

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

from math import *

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

Submission status: Accepted

Solution code:
def N():
    return int(input())
def L():
    return list(map(int,input()))
def NL(n):
    return [list(map(int,input())) for _ in range(n)]
import math
k = N() + 1
sum = 0
for i in range(1,k):
    for j in range(1,k):
        for l in range(1,k):
            #print(sum)
            sum += math.gcd(math.gcd(i,j),l)
print(sum)

Submission status: Accepted

Solution code:
import math
K = int(input())
ans = 0
for i in range(K):
  for t in range(K):
    for j in range(K):
      gcd1 = math.gcd(i+1,t+1)
      gcd2 = math.gcd(gcd1,j+1)
      ans += gcd2
print(ans)

Submission status: Accepted

Solution code:
from math import *

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

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

Submission status: Accepted

Solution code:
from math import gcd
K=int(input())
g=0
for a in range(1,K-1):
  for b in range(a+1,K):
    for c in range(b+1,K+1):
      g+=gcd(gcd(a,b),c)*6
for  d in range(1,K):
  for e in range(d+1,K+1):
    g+=gcd(d,e)*6
g+=K*(K+1)//2
print(g)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

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(gcd(x,y),z)

print(ans)

Submission status: Accepted

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

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


temp = []

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            temp.append(gcd(i,j,k))
print(sum(temp))

Submission status: Accepted

Solution code:
K = int(input())

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

result = 0

for a in range(1, K+1):
    result += a
    #print('{} add'.format(a))
    b = a + 1
    while b <= K:
        result += 6 * gcd(a, b)
        #print('{} and {} add'.format(a, b))
        l = gcd(a, b)
        c = b + 1
        while c <= K:
            result += 6 * gcd(l, c)
            #print('{} and {} and {} add'.format(a, b, c))
            c+= 1
        b += 1
print(result)

Submission status: Accepted

Solution code:
import math


def main():
    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

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(gcd(x,y),z)

print(ans)

Submission status: Accepted

Solution code:
k = int(input())
ans = 0
def gcd(a,b):
    if a % b == 0:
        return b
    c = a % b
    return gcd(b,c)

for l in range(1,k+1):
    for m in range(l,k+1):
        for n in range(m,k+1):
            tmp1 = gcd(l,n)
            tmp2= gcd(tmp1,m)
            if (l==m==n):
                ans+=tmp2
            elif(l==m or m==n):
                ans+= 3*tmp2
            else:
                ans += 6*tmp2


print(ans)

Submission status: Accepted

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


k = int(input())
ans = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            d = gcd(a, b)
            if len({a, b, c}) == 1:
                ans += gcd(c, d)
            elif len({a, b, c}) == 2:
                ans += 3 * gcd(c, d)
            else:
                ans += 6 * gcd(c, d)
print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)
k = int(input())
ans = 0
for a in range(1,k+1):
  for b in range(a,k+1):
    for c in range(b,k+1):
      d = gcd(a, b)
      if len({a,b,c}) == 1:
        ans += gcd(c, d)
      elif len({a,b,c}) == 2:
        ans += 3*gcd(c, d)
      else:
        ans += 6*gcd(c, d)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd
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(gcd(x,y),z)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict,deque

input = sys.stdin.readline
def inar():
    return [int(el) for el in input().split()]
def find(a,b,c):
    gc=math.gcd(a,b)
    return math.gcd(gc,c)
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):
                ans+=find(i,j,k)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

K = int(input())

sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    temp = math.gcd(i,j)
    for k in range(1,K+1):
      sum+=math.gcd(temp,k)
print (sum)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
kotae = []
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            s = i
            t = j
            u = k
            x = 1
            while x != 0:
                v = t%s
                if v != 0:
                    t = s
                    s = v
                else:
                    t = s
                    x = u%t
                    if x != 0:
                        u = t
                        t = x
                    else:
                        kotae.append(t)
print(sum(kotae))