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:
import sys
import fractions, math
from functools import reduce

def gcd(i, j, k):
    return fractions.gcd(i, fractions.gcd(j, k))

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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

tb = [
    [math.gcd(a, b) for a in range(0, 201)]
    for b in range(0, 201)
]

x = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        t = tb[min(a, b)][max(a, b)]
        for c in range(1, k + 1):
            x += tb[min(t, c)][max(t, c)]
print(x)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
if __name__ == "__main__":
    n = int(input())

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

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

k=int(input())
count = 0

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

print(count)

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

gcd = lambda *numbers: reduce(math.gcd, numbers)

K = int(input())

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

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
K = int(input())
cnt = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += gcd(i,j,k)
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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):
            x = fractions.gcd(i,j)
            y = fractions.gcd(x,l)
            ans += y
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

k = int(input())
result = 0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            result += gcd(x,y,z)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
summ = 0

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

print(summ)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
from fractions 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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


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):
            A = gcd(a,b)
            B = gcd(A,c)
            sum += B
print(sum)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
ans = 0
for a in range(K):
    a += 1
    for b in range(K):
        b += 1
        tmp = gcd(a, b)
        for c in range(K):
            c += 1
            ans += gcd(tmp, c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions
k = int(input())
nums = [i for i in range(1,k+1)]
alist = []
ans = 0
for balls in itertools.product(nums, repeat=3):
  alist.append(balls)
for i in alist:
  ans += fractions.gcd(i[0],fractions.gcd(i[1],i[2]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import lru_cache

@lru_cache(maxsize=None)
def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)


k = int(input())
answer = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ary = [a, b, c]
            ary.sort()
            answer += gcd(ary[0], ary[1], ary[2])

print(answer)

Submission status: Time Limit Exceeded

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

Solution code:
import math
from functools import reduce

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

k = int(input())
t = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            t += gcd(i,j,l)
print(t)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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


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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import math
from functools import reduce

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

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

def main():
    n = int(input())
    sumv = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                sumv += gcd(i, j, k)
                #print(i,j,k)
    print(sumv)
  
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())
r = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

a=input()
a=int(a)
sum=0

def gcda(x,y,z):
    temp=math.gcd(x,y)
    return math.gcd(temp,z)

for i in range(1,a+1):
    for j in range(1,a+1):
        for k in range(1,a+1):
            sum+=gcda(i,j,k)

print(sum)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

sum_val = 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):
      sum_val += gcd(a,b,c)
print(sum_val)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
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):
            ans += reduce(math.gcd, [i, j, h])
print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
gcd = [[0 for _ in range(200)] for _ in range(200)]
for i in range(200):
  for j in range(200):
    big = i+1
    sml = j+1
    while sml != 0:
      big,sml = sml,big%sml
    gcd[i][j] = big
#print(gcd)
ans = 0
for a in range(n):
  for b in range(n):
    for c in range(n):
      x = gcd[a][b]
      y = gcd[a][c]
      ans += gcd[x-1][y-1]
      #print(a,b,c,x,y,gcd[x][y])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
k = int(input())
#n, k = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

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

def main():
    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, j, l)
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import math
N= int(input())
a=0
b=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: Time Limit Exceeded

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
@lru_cache(maxsize=None)
def f(a,b):
    return math.gcd(a,b)
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+=f(a,f(b,c))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            s = {i,j,k}
            s = tuple(s)
            if s in memo.keys():
                ans += memo[s]
            else:
                tmp = math.gcd(j,k)
                tmp = math.gcd(tmp,i)
                ans += tmp
                memo[s] = tmp

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K=int(input())
count=0
for t in range(K):
    for s in range(K):
        for v in range(K):
            count+=(gcd(t+1,s+1,v+1))
print(count)

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
memo = [[-1 for i in range(k+1)] for j in range(k+1)]
def gcd(a, b):
    if b == 0:
        return a
    else:
        if memo[a][b] == -1:
            memo[a][b] = gcd(b, a % b)
        return memo[a][b]
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: Time Limit Exceeded

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

sum=0

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

print(sum)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

@lru_cache(maxsize=None)
def solve(x, y, z):
    x2 = math.gcd(x, y)
    return math.gcd(x2, z)

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

    ans = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                x = [i, j, k]
                x.sort()
                ans += solve(x[0], x[1], x[2])

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

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

k = int(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

k = int(input())
total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1, k+1):
            total += gcd(i,j,l)
print(total)

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

n = int(input())
ans = 0

for i in range(1, n+1):
    for ii in range(1, n+1):
        for iii in range(1, n+1):
            ans += gcd3(i,ii,iii)

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)

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

Submission status: Time Limit Exceeded

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

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

Solution code:
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        S=list(i)
        ans+=reduce(gcd,S)
    print(ans)


resolve()

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
K = int(input())

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

ans = 0
#count = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    for k in range(1, K + 1):
      #count += 1
      #print(count, gcd3(i, j, k))
      ans += gcd3(i, j, k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K = int(input())

res = 0

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

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
k = int(input())
cnt = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            cnt += fractions.gcd(i,fractions.gcd(j,m))
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())

res = 0

from math import gcd
from functools import reduce
def find_gcd(list):
    x = reduce(gcd, list)
    return x

for a in range(1, k+ 1):
    for b in range(1, k+1):
        for c in range(1, k+ 1):
            res += find_gcd([a,b,c])

print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce


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


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

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

    print(total)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
k = int(input())
t = list(map(lambda x:list(x),itertools.product([i+1 for i in range(k)],repeat=3)))
ans = 0
for i in range(len(t)):
    ans += math.gcd(math.gcd(t[i][0],t[i][1]),t[i][2])
print(ans)

Submission status: Time Limit Exceeded

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

def gcd(a,b): 
      
    # Everything divides 0  
    if (b == 0): 
         return a 
    return gcd(b, a%b) 
    
def pgcd(a,b,c):
	return gcd(c,gcd(a,b))

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

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

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

K = int(input())
total = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import random
import sys
import heapq
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, UserString
from functools import lru_cache, cmp_to_key, reduce
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)

sys.setrecursionlimit(10**7)
MAX_INT = 2**62-1

input = sys.stdin.buffer.readline

@lru_cache(None)
def gcd(a, b):
    if not b:
        return a
    return gcd(b, a%b)

if __name__ == "__main__":
    n = int(input())
    ans = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                ans += gcd(i, gcd(j, k))
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce


ans = 0
K = int(input())
for a in (range(1, K+1)):
    for b in range(a, K+1):
        for c in range(b, K+1):
            n = 0
            if a == b == c:
                n = 1
            elif a == b or b == c or c == a:
                n = 3
            else:
                n = 6
            ans += n * reduce(gcd, [a,b,c])
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 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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

K=int(input())

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce

K=int(input())

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

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

print(sum)