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: Wrong Answer

Solution code:
def gcd(a,b):
	i = a
	j = b
	while i!=j:
		if i > j:
			i = i-j
		else :
			j = j - i
	return i

k = int(input())

ret = 0
for i in range(1,k+1):
	for j in range(i,k+1):
		for l in range(j,k+1):
			g = gcd(i,gcd(j,l))
			if (i == j) and (j == l):
				m = 1
			elif (i == j) or (j == l) or (l == i):
				m = 2
			else :
				m = 6
			#print("i:",i," j:",j," l:",l," gcd:", g," m:",m)
			ret += g*m
print(ret)

Submission status: Wrong Answer

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k):
        for j in range(1, k+1):
            sum += gcd(i, j)*3

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k-1):
        for j in range(i+1, k):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

Submission status: Wrong Answer

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k+1):
        for j in range(1, k+1):
            sum += gcd(i, j)*3

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k-1):
        for j in range(i+1, k):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

Submission status: Wrong Answer

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k+1):
        for j in range(1, k+1):
            sum += gcd(i, j)*3

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k+1):
        for j in range(i+1, k+1):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

Submission status: Wrong Answer

Solution code:
from math import gcd
N = int(input())
ans = sum([gcd(gcd(i,j),k) for i in range(N+1) for j in range(N+1) for k in range(N+1)])
print(ans)

Submission status: Wrong Answer

Solution code:
import math


num = int(input())
ans = 0

for a in range(num):
    for b in range(num):
        for c in range(num):
            ans += math.gcd(math.gcd(a,b), c)

print(ans)

Submission status: Wrong Answer

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

    K=int(input())
    cal=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            i=gcd(a,b)

        for c in range(1,K+1):
            cal+=gcd(i,c)

    print(cal)


main()

Submission status: Wrong Answer

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

def sum_of_gcd(k):
  ans = 0
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      for k in range(1, k + 1):
        if i < j and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans

n = int(input())
print(sum_of_gcd(n))

Submission status: Wrong Answer

Solution code:
import math

def triple_gcd(a, b, c):
    gcd = 0
    gcd = math.gcd(a, b)
    if(gcd >math.gcd(a, c)):
        gcd = math.gcd(a,c)
    if(gcd > math.gcd(b, c)):
        gcd = math.gcd(b,c)
    return gcd

num = int(input())
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:return y
    else:
        while(x%y!=0):
            z=x%y
            x=y
            y=z
        return z

K = list(map(int, (stdin.readline().strip().split())))[0]
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if i==j:
                ans+=gcd(i,gcd(j,k))*3
                ij=True
print(ans)

Submission status: Wrong Answer

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

def gcd_m(*args):
    a, b = args[0], args[1]
    for i in range(2, len(args)):
        a, b = gcd(a, b), args[i]

    return gcd(a, b)

log = {}
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):
            if a+b+c in log:
                sum_gcd += log[a+b+c]
            else:
                result = gcd_m(a, b, c)
                sum_gcd += result
                log[a+b+c] = result
print(sum_gcd)

Submission status: Wrong Answer

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())
A = 0

for a in (1, K):
    for b in (1, K):
        for c in (1, K):
            print(a,b,c)
            i = gcd(a,b,c)
            print(i)
            A = A + i

print (int(A))

Submission status: Wrong Answer

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

print(ans*3)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

mat = [[0 for i in range(201)] for j in range(201)]
print(len(mat), len(mat[0]))

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

sm = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sm += mat[mat[a][b]][c]

print(sm)

Submission status: Wrong Answer

Solution code:
from numba import njit
from math import gcd

K = int(input())

@njit
def solve():
    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: Wrong Answer

Solution code:
# 最小公倍数(ユーグリッド互除法)
def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd( b, a % b)


K = int(input()) + 1
mydict = {}

# データパターンを求める式
ans = 0
for h in range(1, K):
  ans += (gcd(h,gcd(h,h)) * 3)
  for i in range(h+1, K-1):
    ans += (gcd(h,gcd(h,i)) * 3)
    for j in range(i+1, K):
      ans += (gcd(h,gcd(i,j)) * 3)
      
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

def gcd2(x,y):
  x,y = max(x,y),min(x,y)
  r = x%y
  while r!=0:
    x = y
    y = r
    r = x % y
  return y*2
 
def gcd3(x,y,z):
  if x == y == z:
    return x
  elif x != y != z != x:
    r = 0
    l = []
  
    while x!=0 and y!=0 and z!=0 :
      l = sorted([abs(x-y),abs(y-z),abs(z-x)])
      while  l==[] or l[0]==0:
        if l!=[]:
          l.pop(0)
      if len(l)>0:
        r = l[0]
        x %= r
        y %= r
        z %= r
      else:
        return x
    #end of while
    return r*6
  else:
    if x==y:
      return gcd2(z,x)
    elif y==z:
      return gcd2(x,y)
    else:
      return gcd2(y,z)
#end of def
 
for a in range(1,K+1):
  for b in range(1,a+1):
    for c in range(1,b+1):
      ans += gcd3(a,b,c)
#end of for
 
print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())

ans = 0

import math

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

print(ans)

Submission status: Wrong Answer

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

def gcd(x,y,z):
  r = 0
  while x!=0 and y!=0 and z!=0 :
    r = -min(-abs(x-y),-abs(y-z),-abs(z-x))
    if r == 0:
      return x
    x %= r
    y %= r
    z %= r
  return r
#end of def

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)
#end of for

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
dic = {}
def gcd1(x, y):
  while(y):
    x, y = y, x % y 
  return x
 
def gcd(a,b,c):
  s = str(a) + str(b) + str(c)
  if s in dic.keys():
    return(dic[s])
  else:
    ans = gcd1(a,gcd1(b,c))
    dic[s] = ans
  return(ans)
 
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,b,c)
print(sum)

Submission status: Wrong Answer

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



N = int(input())

s = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            s +=euclidean(euclidean(i+1,j+1),k+1)

Submission status: Wrong Answer

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):
           ab = math.gcd(i,j)
           abc = math.gcd(ab,l)
           print(i,j,l)
           ans += abc
'''
           
for i in range(1,K+1):
    for j in range(i,K+1):
        for l in range(j,K+1):
           ab = math.gcd(i,j)
           abc = math.gcd(ab,l)
           print(i,j,l)
           if i == j and j == l:#３つすべて同じ数字のとき
               abc = abc
               #print('abc',abc)
           elif i == j or j == l or i == l:#２つの数字が同じ時
               abc = 3*abc
               #print('abc',abc)
           elif i != j and i != l and j != l:#３つの数字がすべて違うとき
               abc = 6*abc
               #print('abc',abc)
           
           ans += abc
           #print(ans,abc)


print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

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):
           ab = math.gcd(i,j)
           abc = math.gcd(ab,l)
           print(i,j,l)
           ans += abc
'''
           
for i in range(1,K+1):
    for j in range(i,K+1):
        for l in range(j,K+1):
           ab = math.gcd(i,j)
           abc = math.gcd(ab,l)
           #print(i,j,l)
           if i == j and j == l:#３つすべて同じ数字のとき
               abc = abc
               #print('abc',abc)
           elif i == j or j == l or i == l:#２つの数字が同じ時
               abc = 3*abc
               #print('abc',abc)
           elif i != j and i != l and j != l:#３つの数字がすべて違うとき
               abc = K*(K-1)*abc
               #print('abc',abc)
           
           ans += abc
           #print(ans,abc)


print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import gcd

k = int(input())
ans = 0

li = []
li2 = [[-1] * (k+1) for _ in range(k+1)]

for _ in range(k):
    li.append(li2)


for i in range(k):
    for j in range(k):
        for ii in range(k):
            li3 = sorted([i,j,ii])
            if li[li3[0]][li3[1]][li3[2]] != -1:
                ans += li[li3[0]][li3[1]][li3[2]]
            else:
                a = gcd(i+1,gcd(j+1,ii+1))
                li[li3[0]][li3[1]][li3[2]] = a
                ans += a

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
gcd_list=[]
i=int(input())
for x in range(i):
  for y in range(i):
    for z in range(i):
      gcd_list.append(gcd(x, y, z))
print(sum(gcd_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from functools import reduce

def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def mgcd(*a):
    return reduce(gcd, a)

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):
      tmp = mgcd(i, j, l)
      if i == j== k:
        ans += tmp
      else:
        ans += tmp*3
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#C
#入力
K=int(input())+1


#デバッグ用
def pront(*n):
    if debug==1:
        print(n)
        
debug=1#0:本番,1:デバッグ

#処理
import math as m

Z=[ [ [-1 for i in range(K)] for j in range(K)] for l in range(K)]
def C_1(i,j,k):
    xx=[i,j,k]
    xx.sort()
    if Z[xx[0]][xx[1]][xx[2]]!=-1:
        return Z[xx[0]][xx[1]][xx[2]]
    else:
        Z[xx[0]][xx[1]][xx[2]]=m.gcd(m.gcd(xx[0],xx[1]),xx[2])
        return Z[xx[0]][xx[1]][xx[2]]


x=0
for i in range(1,K):
    for j in range(1,K):
        if m.gcd(i,j)==1:
            x+=K
        else:
            for k in range(1,K):
                x+=C_1(i,j,k)
print(x)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
k=int(input())
c=0
for i in range(1,k+1):
    for j in range(k):
        for t in range(k):
            p=gcd(i,j)
            q=gcd(p,t)
            c+=q
print(c)

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    print('Yes') if '7' in n else print('No')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import math

k = int(input())
klis = list(range(1,k+1))
lis = list(itertools.product(klis, klis, klis))

def gcd2(x):
    return math.gcd(x[0],math.gcd(x[1],x[2]))

result = map(gcd2, lis)
sum(list(result))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from math import gcd
from math import ceil, floor
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    ans = 0
    for a in range(1, n+1):
        for b in range(1, n+1):
            tmp = gcd(a, b)
            for c in range(1, n+1):
                ans += gcd(tmp, c)
    print(c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
GCD = [[math.gcd(i, j)-1 for i in range(1, N+1)] for j in range(1, N+1)]
#print(GCD)
all_gcd = [GCD[GCD[i][j]][m] for i in range(N) for j in range(N) for m in range(N)]
print(sum(all_gcd))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from itertools import permutations
from math import gcd

# def gcd(a, b):
#     # ユークリッドの互除法による最大公約数
#     if b == 0:
#         return a
#     return gcd(b, a % b)


def make_key1(i, j):
    return '-'.join([str(val) for val in sorted([i, j])])


def make_key2(i, j, k):
    return '-'.join([str(val) for val in sorted([i, j, k])])


if __name__ == '__main__':
    K = int(input())
    ans = 0
    mem = defaultdict()
    for i in range(1, K + 1):
        for j in range(1, K + 1):
            for k in range(1, K + 1):
                set_ijk = list(set([i,j,k]))
                if len(set_ijk) == 1:
                    ans += i
                elif len(set_ijk) == 2:
                    key1 = make_key1(*set_ijk)
                    if key1 in mem:
                        ans += mem[key1]
                    else:
                        gcd1 = gcd(*set_ijk)
                        ans += 1
                        mem[key1] = gcd1
                else:
                    key1 = make_key1(i, j)
                    if key1 not in mem:
                        gcd1 = gcd(i, j)
                        mem[key1] = gcd1
                    else:
                        gcd1 = mem[key1]

                    key2 = make_key1(gcd1, k)
                    if key2 not in mem:
                        gcd2 = gcd(gcd1, k)
                        mem[key2] = gcd2
                    else:
                        gcd2 = mem[key2]
                    ans += gcd2

    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import functools
import scipy.special

k = int(input())
def sum_of_gcd(k, n):
    t = 0
    for i in range(1, 4):
        c = itertools.combinations(range(1, k + 1), i)
        cc = map(lambda x: functools.reduce(math.gcd, x), c)
        c2 = scipy.special.comb(k, i - 1, exact=True)
        s = sum(cc) * c2
        t += s
print(sum_of_gcd(k, 3))

Submission status: Wrong Answer

Solution code:
import scipy as sp
import numpy as np
import math


N = int(input())

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

            ans += math.gcd(c, d)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
from numba import jit

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 21:45:38 2020
 
@author: H_Hoshigi
"""
 
import math
 
K = 200#int(input())
 
answer = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            answer += math.gcd(math.gcd(a, b), c)
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import gcd
g=[201*[0]for _ in range(201)]
for i in range(1,201):
  for j in range(i,201):
    g[i][j]=gcd(i,j)
ans=0
for i in range(1,201):
  for j in range(i,201):
    anss=0
    for k in range(j,201):
      m=g[min(i,j)][max(i,j)]
      m=g[min(k,m)][max(k,m)]
      if k!=j:anss+=m
      anss+=m
    if i!=j:ans+=anss
    ans+=anss
print(ans)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = math.gcd(a, b)
        cnt = sum([math.gcd(tmp, c) for c in range(1, K+1)])
print(cnt)

Submission status: Wrong Answer

Solution code:
a=int(input())
counter=0
for i in range(1,a+1):
    for j in range(i,a+1):
        for k in range(j,a+1):
            if i==j and j==k:
                times=1
            elif i!=j and j!=k and k!=i:
                times=6 
            else:
                times=3
            
            for l in range(i,0,-1): 
                if j%l==0 and k%l==0:
                    counter+=(l*times)
                    break
print(counter)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        if ab == 1:
            ans += k
            continue
    for k in range(1, k+1):
        ans += math.gcd(ab,k)

print(ans)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b > a:
    c = a
    a = b
    b = c
  while b != 0:
    a = b
    b = a % b
  return a
k = int(input())
ans = 0
for ind0 in range(1,k+1):
  for ind1 in range(1,k+1):
    for ind2 in range(1,k+1):
      ans += gcd(gcd(ind0,ind1),ind2)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd


K = int(input())
ans = 0

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

Submission status: Wrong Answer

Solution code:
n=int(input())
# a,b,c=map(int,input().split())
cnt=0
def gcd(a,b):
    if a==0: return b
    else: return gcd(b%a,a)
# print(gcd(a,b))

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

for i in range(1,n+1):
    for j in range ( 1 , n + 1 ):
        for k in range ( 1 , n + 1 ):
            # cnt+=gcd_3(i,j,k)
            cnt+=1


print(cnt)

Submission status: Wrong Answer

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

def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A1 = [0,0]
A2 = [0,0,0]
for i in range(1, K):
    S = S + i

if K > 1:
    for j in range(1, K):
        A1[0] =  j
        for k in range(j+1,K+1):
            A1[1] = k
            S += 6 * gcd(A1[1],A1[0])

if K > 2:
    for i1 in range(1, K-1):
        A2[0] = i1
        for k1 in range(i1+1, K):
            A2[1] = k1
            for j1 in range(k1+1,K+1):
                A2[2] = j1
                G3 = gcd(A2[2],A2[1])
                if G3 >= A2[0]:
                    S += 6 * gcd(G3,A2[0])
                else:
                    S += 6 * gcd(A2[0],G3)
                    
print(S)

Submission status: Wrong Answer

Solution code:
from math import gcd

K=int(input())+1
sum=0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

K = int(input())

gcdSum = 0

myArr = np.zeros((K, K), dtype=int)

for iIndx in range(K):
    for jIndx in range(K):
        myArr[iIndx, jIndx] = math.gcd(iIndx, jIndx)

for iIndx in range(K):
    for jIndx in range(K):
        presGcd = myArr[iIndx, jIndx]
        for kIndx in range(K):
            gcdSum += myArr[presGcd, kIndx]

print(gcdSum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools as it
from collections import Counter

d = {}
def gcd(a,b):
    a, b = max(a,b), min(a,b)
    while b:
        if d.get((a, b), False):
            return d[(a, b)]
        else:
            a, b = b, a%b

    d[(a, b)] = a
    return a

# def solve(K: int):
#     r = range(1, K+1)

#     arr = []
#     for (a,b) in it.product(r,r):
#         arr.append(gcd(a,b))

#     ans = 0
#     cnt_dict = Counter(arr)
#     for i in r:
#         for key, cnt in cnt_dict.items():
#             ans += gcd(i,key)*cnt

#     print(ans)
    # return

def solve(K: int):
    r = range(1, K+1)
    ans = 0
    d = {}

    for _ in it.product(r,r,r):	
        a, b, c = sorted(_)
        _a, _b, _c = a, b, c
        while c:
            if d.get((b, c), False):
                b = d[(b, c)]
                break 
            else:
                b, c = b, b%c,
        d[(_b, _c)] = b
        while b:
            if d.get((a, b), False):
                a = d[(a, b)]
                break 
            else:
                a, b = b, a%b
        d[(_a, _b)] = a
        ans += a
    print(ans)
    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: Wrong Answer

Solution code:
def solve(K: int):
    r = range(1, K+1)
    ans = 0
    d = {}

    for _ in it.product(r,r,r):	
        a, b, c = sorted(_)
        _a, _b, _c = a, b, c
        while c:
            if d.get((b, c), False):
                b = d[(b, c)]
                break 
            else:
                b, c = b, b%c,
        d[(_b, _c)] = b
        while b:
            if d.get((a, b), False):
                a = d[(a, b)]
                break 
            else:
                a, b = b, a%b
        d[(_a, _b)] = a
        ans += a
    print(ans)
    return

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


n = int(input())
cnt=0
for i in range(1,n+1):
    for j in range(1,n+1):
        if(i==j):
            cnt += i
        else:
            cnt += gcd(i,i,j)*3
 
if(n>=3):
    my_list = list(range(1,n+1))
    x = combinations(my_list, 3)
 
    list_x = list(x)
    for i in list_x:
        cnt+= gcd(i[0],i[1],i[2])
 
print(cnt)

Submission status: Wrong Answer

Solution code:
from math import gcd
k = int(input())+1
n = 0
for i in range(1,k):
  for j in range(i,k):
    for l in range(j, k):
      if i == j == l:
        print([i, j, l])
        print(gcd(i,gcd(j,l)))
        n += gcd(i,gcd(j,l))
      elif i == j or j == l or l == i:
        print([i,j,l])
        print(gcd(i,gcd(j,l))*3)
        n += gcd(i,gcd(j,l))*3
      else:
        print([i,j,l])
        print(gcd(i,gcd(j,l))*6)
        n += gcd(i,gcd(j,l))*6
print(n)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math
import sys
 
K = int(input())
 
def gcd(*args):
  return reduce(math.gcd, args)
 
if K==1:
  print("1")
elif K==2:
  print("9")
  sys.exit()
 
ans = K * (K+1)//2
for i in range(1,K):
  for j in range(i+1,K+1):
    ans += 6*math.gcd(i,j)
  
for i in range(1,K-1):
  for j in range(i+1, K):
    for k in range(j+1, K+1):
      ans += 6 * gcd(i,j,k)
      
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
def gcd(*number):
    return reduce(math.gcd, number)
n = int(input())
a, b, c = 1, 1, 1
sum = 0
list_number = []
while True:
    print(a,b,c)
    list_number.append(gcd(a, b, c))
    if n > c:
        c += 1
    elif n == c and n == b and n == a:
        break
    elif n == c and n == b:
        a += 1
        b = 1
        c = 1
    elif n == c:
        b += 1
        c = 1
for i in list_number:
    sum = sum + i
print(sum)