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:
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
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):
            x = a
            x = gcd(x,b)
            x = gcd(x,c)
            cnt += x
print(cnt)

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    from math import gcd
    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)


if __name__ == '__main__':
    main()

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

print(num)

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x%y!=0:
        return gcd(y,x%y)
    else:
        return y
def GCD(x,y,z):
    return gcd(gcd(x,y),z)
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):
            ans+=GCD(a,b,c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
#from functools import reduce

k = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
def calc(a, b):
    m = min(a, b)
    l = max(a, b)
    while m != 0:
        s = m
        m = l % m
        l = s
    return l

K = int(input())
ans = 0
for i in range(K):
    for j in range(i+1):
        for k in range(j+1):
            if i == j == k:
                ans += i+1
            elif i == j:
                ans += 3 * calc(i+1, k+1)
            elif j == k:
                ans += 3 * calc(i+1, j+1)
            else:
                ans += 6 * calc(calc(i+1, j+1), k+1)

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
from math import gcd

n = int(sys.stdin.read())
print(sum(gcd(gcd(abc[0], abc[1]), abc[2]) for abc in itertools.product(range(1, n + 1), repeat=3)))

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
import functools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
k = inp()
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += functools.reduce(euclid,[a,b,c])

print(ans)

Submission status: Accepted

Solution code:
from math import gcd
from itertools import product
from functools import reduce

l1 = [i for i in range(1, int(input()) + 1)]
print(sum(reduce(gcd, l) for l in product(l1, repeat=3)))

Submission status: Accepted

Solution code:
import math
from functools import reduce

K = int(input())

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

ans = 0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i == j  == k:
        ans += gcd(i,j,k)
      elif i == j or j == k:
        ans += 3*gcd(i,j,k)
      else:
        ans += 6*gcd(i,j,k)
      # print(f'i,j,k:{i},{j},{k}, ans:{gcd(i,j,k)}')
print(ans)

Submission status: Accepted

Solution code:
import math

def sum_of_gcd_of_tuples():
    # 入力
    K = int(input())
    # 初期処理
    sum_gcd = 0
    # 処理
    for a in range(1,K+1):
        for b in range(1,K+1):
            for c in range(1,K+1):
                gcd_num = math.gcd(a,b)
                gcd_num = math.gcd(gcd_num,c)
                sum_gcd += gcd_num
    return sum_gcd

result = sum_of_gcd_of_tuples()
print(result)

Submission status: Accepted

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

import math

def main():

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline


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


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

Submission status: Accepted

Solution code:
import itertools
import math

K = int(input())
nums = range(1, K + 1)
comb = itertools.combinations_with_replacement(nums, 3)
ans = 0

for v in comb:
    n1 = math.gcd(v[0], v[1])
    n2 = math.gcd(n1, v[2])
    l = len(list(set(v)))
    if l == 3:
        ans += 6 * n2
    elif l == 2:
        ans += 3 * n2
    elif l == 1:
        ans += n2
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):
    ab = math.gcd(a,b)
    for c in range(1,k+1):
      sum += math.gcd(ab,c)
print(sum)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import functools
import math
import sys

INF = float('inf')


def solve(K: int):

    @functools.lru_cache(maxsize=K**3)
    def gcd(a: int, b: int) -> int:
        return math.gcd(a, b)

    return sum([gcd(ab, c+1) for ab in [gcd(a+1, b+1) for a in range(K) for b in range(K)] for c in range(K)])


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    print(f'{solve(K)}')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
import math
res=0
for a in range(1,n+1):
    for b in range(1, n + 1):
        gcd1 = math.gcd(a, b)
        for c in range(1, n + 1):
           gcd2=math.gcd(gcd1,c)
           res+=gcd2
print(res)

Submission status: Accepted

Solution code:
from sys import stdin
import math
from functools import reduce

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

k = int(stdin.readline().rstrip())

d = 0
for i in range(1,k+1):
    for j in range(i+1,k+1):
        for l in range(j+1,k+1):
            d = d + 6*reduce(gcd, [i,j,l])

for i in range(1,k+1):
    for j in range(1,k+1):
        if j != i: d = d + 3*reduce(gcd, [i,j])

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

print (d)

Submission status: Accepted

Solution code:
from math import gcd

k = int(input())

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

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):
    ab = math.gcd(a,b)
    for c in range(1,k+1):
      sum += math.gcd(ab, c)

print(sum)

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
n = int(input())+1
sum0 = 0
for i in range(1,n):
    for j in range(1,n):
        a=math.gcd(i,j)
        for k in range(1,n):
            sum0 += math.gcd(a,k)
print(sum0)

Submission status: Accepted

Solution code:
from math import gcd

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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):
    for c in range(1,K+1):
      ans += math.gcd(a,math.gcd(b,c))
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:
from math import gcd

k = int(input())

wa = 0

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


print(wa)

Submission status: Accepted

Solution code:
import math
from functools import reduce
import sys
sys.setrecursionlimit(2000000)

k = int(input())

wa = 0

for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            li = [a,b,c]
            wa += reduce(math.gcd,li)*6

for a in range(1,k+1):
    for b in range(a+1,k+1):
        wa += math.gcd(a,b)*6

for a in range(1,k+1):
    wa += a
    

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

Submission status: Accepted

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

# 全部同じのケース
for i in range(1,k+1):
    s += gcd(i,gcd(i,i))

# １つ違うケース
for i in range(1,k+1):
    for j in range(1,k+1):
        if i != j:
            s += gcd(i,gcd(i,j))*3

# 全部違うケース
for a in range(1,k-1):
    for b in range(a+1,k):
        for c in range(b+1,k+1):
            s += gcd(a,gcd(b,c))*6
            
print(s)

Submission status: Accepted

Solution code:
# -*- conding: utf-8 -*-
import math
K = int(input())

ans = 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):
      ans += math.gcd(x, c)
print(ans)

Submission status: Accepted

Solution code:
k=int(input())

ans=0
import itertools
import math
for seq in itertools.combinations_with_replacement(range(1,k+1),3):
    if seq[0]==seq[1] or seq[1]==seq[2]:
        if  seq[0]!=seq[2]:
            ans+=(math.gcd(seq[0],math.gcd(seq[1],seq[2])))*3
        else:
            ans+=math.gcd(seq[0],math.gcd(seq[1],seq[2]))

    else:
        ans+=math.gcd(seq[0],math.gcd(seq[1],seq[2]))*6
print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)
import collections
K = int(input())
ans = 0
cnt = collections.defaultdict(int)
# count the number of combination of a, b
for a in range(1, K + 1):
  for b in range(1, K + 1):
    cnt[gcd(a, b)] += 1
for c in range(1, K + 1):
  for gcd_of_ab in cnt.keys():
    ans += gcd(gcd_of_ab, c) * cnt[gcd_of_ab]
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce
k = int(input())
ans = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

print(ans)

Submission status: Accepted

Solution code:
import math
import itertools

k = int(input())
l = list(range(1,k+1))
y = list(itertools.combinations_with_replacement(l,3))
n = len(y)
t = 0

for i in range(n):
    a = y[i][0]
    b = y[i][1]
    c = y[i][2]
    d = math.gcd(math.gcd(a,b),c)
    if a != b != c:
        t += d * 6
    elif a == b == c:
        t += d
    else:
        t += d * 3

print(t)

Submission status: Accepted

Solution code:
# C Sum of gcd of Tuples (Easy)

import math
from itertools import combinations_with_replacement as C

K = int(input())

ans = 0
ABC = list(C(range(1, K+1), 3))
for a, b, c in ABC:
  if a == b == c:
    ans += math.gcd(math.gcd(a, b), c)
  elif a == b or b == c or c == a:
    ans += math.gcd(math.gcd(a, b), c) * 3
  else:
    ans += math.gcd(math.gcd(a, b), c) * 6
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += gcd(gcd(a,c),b)
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):
        num = math.gcd(a,b)
        for c in range(1,K+1):
            ans += math.gcd(num,c)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
k = int(input())
x = np.arange(1,k+1)
# np.ufunc.outer: c_ij = f(a_i, b_j)
a = np.gcd.outer(np.gcd.outer(x,x),x)
print(a.sum())

Submission status: Accepted

Solution code:
k = int(input())

from math import gcd

ans = 0

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

print(ans)

Submission status: Accepted

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

k = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from math import gcd

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


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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())

def gcd(x,y):
    if x<y:
        temp=x
        x=y
        y=temp
    if x%y==0:
        return y
    else:
        nx=y
        ny=x%y
        return gcd(nx,ny)
ans=0
for a in range(1,K+1):
    for b in range(1,K+1):
        g=gcd(a,b)
        for c in range(1,K+1):
            ans+=gcd(g,c)

print(ans)

Submission status: Accepted

Solution code:
K=int(input())

from math import gcd

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
ans=0

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(A[N-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(out)

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

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

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

print(sum)

Submission status: Accepted

Solution code:
k = int(input())

sum = 0

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


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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:48:51 2020

@author: Aruto Hosaka
"""


import math
import collections

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from math import gcd

K = int(input())

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

print(a)

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

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

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

print(ans)

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:
k = int(input())

from math import gcd

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

print(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
from collections import Counter
k=int(input())
t=[]
for a in range(1,k+1):
  for b in range(1,k+1):
    t.append(gcd(a,b))      
t=Counter(t)
ans=0
for d,e in t.items():
  for c in range(1,k+1):
    g=gcd(c,d)
    ans+=g*e
print(ans)