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

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

print(ans)

Submission status: Accepted

Solution code:
import math
import itertools
K = int(input())
ans = 0
for x in itertools.product(list(range(1,K+1)), repeat = 3):
    [a,b,c] = x
    ans += math.gcd((math.gcd(a,b)),c)
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):
        tmp = gcd(i, j)
        for k in range(1, K + 1):
            ans += gcd(tmp, k)

print (ans)

Submission status: Accepted

Solution code:
import os

import itertools
import sys
from math import gcd

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

K = int(sys.stdin.buffer.readline())

# memo = [[0] * 201 for _ in range(201)]
# for a, b in itertools.product(range(201), repeat=2):
#     memo[a][b] = gcd(gcd(a, b), c)

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

Submission status: Accepted

Solution code:
from math import gcd

ans = 0
k = int(input().strip())
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:
def main():
    from math import gcd

    K = int(input())

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


main()

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

print(s)

Submission status: Accepted

Solution code:
k = int(input())

# a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

ansl = [[gcd(i, j) for i in range(201)] for j in range(201)]

ans = 0
for i in range(1,k+1):
    for j in range(1, k + 1):
        p = ansl[i][j]
        for k in range(1, k + 1):
            ans += ansl[p][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):
        for k in range(1, K+1):
            ans += gcd(gcd(i, j), k)
            
print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import math

k = int(input())
s = 0

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

Submission status: Accepted

Solution code:
K = int(input())

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

ret = 0

x = [0] * (K + 1)
for a in range(1, K + 1) :
  for b in range(1, K + 1) :
    x[gcd(a, b)] += 1

for c in range(1, K + 1) :
  for d in range(1, K + 1) :
    ret += gcd(c, d) * x[d]
    
print(ret)

Submission status: Accepted

Solution code:
from math import gcd as g
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 += g(g(a, b), c)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
import math
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            tmp=math.gcd(i,j)
            ans+=math.gcd(tmp,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):
            g = gcd(a, b)
            ans += gcd(g, c)
print(ans)

Submission status: Accepted

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

K = int(input())

res = 0

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

print(res)

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(K: int):
    dp = [[-1] * (K + 1) for _ in range(K + 1)]
    def gcd(a, b):
        if dp[a][b] >= 0:
            return dp[a][b]
        else:
            ret = a if b == 0 else gcd(b, a % b)
        dp[a][b] = ret
        return ret
    ret = 0
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            for k in range(1, K + 1):
                tmp = gcd(i, j)
                ret += gcd(tmp, k)
    print(ret)
    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import time
s = time.time()
import math
K = Int()
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)
g = time.time()

#print(g-s)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
INF = 2**62-1

def read_int():
    return int(input())


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


def main():
    K = read_int()
    print(slv(K))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

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

print(res)

Submission status: Accepted

Solution code:
# GCD
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a

# lのGCD
def gcdlist(l):
    res = l[0]
    for i in range(1,len(l)):
        res = gcd(res, l[i])
    return res

n = int(input())
res = 0

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

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from math import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#C
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:
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    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): 
            ans += gcd(gcd(a, b), 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):
        ab = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(ab, c)
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

Submission status: Accepted

Solution code:
import sys
from math import gcd
input = sys.stdin.readline
N = int(input())
res = 0
for i in range(1, N + 1):
  for j in range(1, N + 1):
    for k in range(1, N + 1):
      res += gcd(gcd(i, j), k)
print(res)

Submission status: Accepted

Solution code:
import sys

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    K = int(input())
    ans = 0
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            ab = gcd(i, j)
            for c in range(1, K + 1):
                ans += gcd(ab, c)
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
import copy
import itertools
n = int(readline())

lst1 = [i for i in range(1,n+1)]
lst2 = copy.deepcopy(lst1)
lst3 = copy.deepcopy(lst1)

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
ans = 0
for i,j,k in itertools.product(lst1,lst2,lst3):
    ans += gcd(i,gcd(j,k))
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import *

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

print(ans)

Submission status: Accepted

Solution code:
k = int(input())
import math
ans = 0
def GCD(a,b,c):
    return math.gcd(math.gcd(a,b),c)
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: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

k=int(input())
ans=0
for i in range(k):
    for j in range(k):
        for l in range(k):
            ans+=gcd(gcd(i+1,j+1),l+1)
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):
            p = gcd(a, b)
            ans += gcd(p, c)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd

k = int(input())

cnt = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        x = gcd(i, j)
        for l in range(1, k + 1):
            cnt += gcd(x, l)
print(cnt)

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#p,n,k,b,*a = [int(i) for i in read().split()]

n = int(input())
from math import gcd
print(sum(gcd(gcd(a,b),c) for a in range(1,n+1) for b in range(1,n+1) for c in range(1,n+1)))

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

print(ans)

Submission status: Accepted

Solution code:
import math
k=int(input())
ans=0
for i1 in range(1,k+1):
  for i2 in range(1,k+1):
    for i3 in range(1,k+1):
      x=math.gcd(i1,i2)
      x=math.gcd(x,i3)
      ans+=x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC162
# A
# B
# C
import math
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+=math.gcd(x,math.gcd(y,z))
print(ans)
# D
# E
# F

Submission status: Accepted

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
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):
            x = gcd(i,j)
            ans += gcd(x,k)
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
# 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 main():
    k = inp()
    ans = 0
    for i in range(k):
        for j in range(k):
            for w in range(k):
                ans += math.gcd(math.gcd(i+1,j+1),w+1)
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import gcd


K, = [int(x) for x in input().split()]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    k = II()
    ans = 0
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            ij = gcd(i, j)
            for l in range(1, k + 1):
                ans += gcd(ij, l)
    print(ans)
    return


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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

g = [] * 201

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

for i in range(201):
    g.append([])
    for j in range(201):
        g[-1].append(gcd(i, j))

n = ni()
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        u = g[i][j]
        for k in range(1,n+1):
            ans += g[u][k]
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):
        d = math.gcd(a,b)
        for c in range(1,k+1):
            ans += math.gcd(d,c)
print(ans)

Submission status: Accepted

Solution code:
def main():
    from math import gcd

    K = int(input())

    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)
    

if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
# ABC162c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    # 最大公約数,最大公約数
    # from fractions import gcd
    from functools import reduce
    from math import gcd

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

    def lcm(*numbers):
        return reduce(lcm_base, numbers, 1)

    def gcds(*numbers):
        return reduce(gcd, numbers)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from math import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    K = I()
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            gcab = math.gcd(a, b)
            for c in range(1, K+1):
                ans += math.gcd(gcab, c)
    print(ans)


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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a, a)
    k = I()
    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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def examA():
    N = SI()
    ans = "No"
    for s in N:
        if s=="7":
            ans = "Yes"
    print(ans)
    return

def examB():
    N = I()
    ans = 0
    for i in range(1,N+1):
        if i%3==0:
            continue
        if i%5==0:
            continue
        ans += i
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    K = I()
    ans = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            cur = gcd(i,j)
            for k in range(1,K+1):
                ans += gcd(cur,k)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
K = int(input())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
    
result = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            result = gcd(i, gcd(j, k)) + result

print(result)

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    mem = defaultdict(lambda : None)
    def gcd(a,b):
        if mem[(a,b)] != None:
            return mem[(a,b)]
        if a == 0:
            mem[(a,b)] = mem[(b,a)] = b
            return b
        mem[(a,b)] = mem[(b,a)] = gcd(b%a,a)
        return mem[(a,b)]
    k = I()
    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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
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: 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 l in range(1, k+1):
            a = gcd(i,j)
            b = gcd(a,l)
            ans += 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):
        for c in range(1,k+1):
            ans += math.gcd(math.gcd(a,b),c)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce


def main():
    l = int(input())
    answer = 0
    for i in range(1, l + 1):
        for j in range(1, l + 1):
            for k in range(1, l + 1):
                answer += reduce(gcd, [i, j, k])
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

def solve():
    n = int(input())
    c = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            a = gcd(i, j)
            for k in range(1, n+1):
                c += gcd(a, k)

    return c

print(solve())