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:
K=int(input())
def gcd(a,b,c):
    if a <b:
        a,b=b,a
    while a%b != 0:
        a,b= b,a%b
    if b < c:
        b,c=c,b
    while b % c != 0:
        b,c = c,b%c
    return c
x=0
for i in range(1,K+1):
    for j in range(1,K+1):
        if not (i==j):
            for l in range(1,K+1):
                if not(j==l):
                    if (i==1) or (j==1) or (l==1):
                        x+=1

                    else:
                        x += gcd(i,j,l)
print(x)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())
ans = 0
lst = []
for a in range(2, k+1):
    for b in range(2, k+1):
      lst.append(math.gcd(a, b))
for d in lst:
  for c in range(2, k+1):
    ans += math.gcd(c, d)
appe = 200**3 - 199**3
ans += appe
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
K = int(input())
sum_gcd = 0
gcd = 0
for a in range(K,0,-1):
    for b in range(K,0,-1):
        for c in range(K,0,-1):
            i = max(a,b,c)
            while i >= min(a,b,c):
                if a == b and b ==c:
                    gcd = a
                elif a % i == 0 and b % i == 0 and c % i == 0:
                   gcd = i  
                   break
                i -= 1
            sum_gcd += gcd
print(sum_gcd)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
k = int(input())
a_list = [a for a in range(1,k+1)]
ab_list = [[math.gcd(aa,b) for aa in a_list] for b in range(1,k+1)]
abc_list = [[[math.gcd(ab_gcd,c) for ab_gcd in ab] for ab in ab_list] for c in range(1,k+1)]
print(abc_list)

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)

import itertools
a=int(input())
A=[]
for i in range(a):
    A.extend(str(i+1))

li=list(itertools.combinations_with_replacement(A, 3))
s = 0
for lis in li:
    a = int(lis[0])
    b = int(lis[1])
    c = int(lis[2])
    
    if math.gcd(b,c) == 1:
        gcd1 = 1
    else:
        gcd1 = gcd(a,b,c)
    
    if a==b and b==c:
        s = s + gcd1
    elif a==b or b==c:
        s = s + 3*gcd1
    else:
        s = s + 9*gcd1
print(s)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

def tripple_gcd(a,b,c):
    a = gcd(a,b)
    return gcd(a,c)

result = [ 3*gcd(i,j) for j in range(1,k+1) for i in range(1,k+1) if i != j]
result += [(k-1)*gcd(i,i) for i in range(1,k+1)]
print(sum(result))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

q = [[str(i)] for i in range(1, K+1)]
# print(q)
s = []
ans = 0
while q:
    a = q.pop()
    # print(q)@
    if len(a) == 3:
        # s.append(a)
        ans += int(a[-1])
        # print(a)
    else:
        for i in range(1, K+1):
            b = deepcopy(a)
            if int(b[-1]) <= i:
                b.append(b[-1])
            # b += str(gcd(i, int(b[-1])))
            else:
                b.append(str(i))
            q.append(b)
print(ans)
# print(s)
# print(s)
# ans = 0
# for d in s:
#     print(sorted(list(d))[0])

# print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import lru_cache
 
def main():
    K = int(input()) + 1
 
    @lru_cache(maxsize=1000000)
    def get_gcd(a, b, c):
        tmp = gcd(a, b)
        return gcd(tmp, c)
 
    result = 0
    for c in range(1, K):
        for b in range(1, K):
            for a in range(1, K):
                sorted_list = [a, b, c]
                sorted_list.sort(reverse=True)
                a, b, c = sorted_list
                result += get_gcd(a, b, c)
    print(result)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import sys
from io import StringIO
import unittest
from functools import reduce


def resolve():
    k = int(input())

    ans = 0

    for a in range(1, k + 1):
        # print(a)
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                work = reduce(math.gcd, [a, b, c])
                # if (a == 1 and b == 1 and c == 1) or (a == k and b == k and c == k) or (a == b == c):
                if a == b == c:
                    # print("これは×3しない")
                    # print(str(a) + "|" + str(b) + "|" + str(c) + "=" + str(work))
                    # ×3しない
                    pass
                else:
                    # print("これは×3する")
                    # print(str(a) + "|" + str(b) + "|" + str(c) + "=" + str(work * 3))
                    work = work * 3
                ans += work

    print(ans)


# これじゃダメ。タイムアウト。
def not_resolve():
    k = int(input())

    ans = 0

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

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例(self):
        input = """3"""
        output = """30"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
import math

# a, b, c= map(int, input().split())
# A = math.gcd(a, b)
# B = math.gcd(A, c)

i = int(input())
L1=[]
L2=[]
L3=[]
L4=[]
L5=[]
L6=[]
L7=[]
a = 1
b = 1
c = 1

for x in range(i):
    r1 = math.gcd(a, b)
    d1 = math.gcd(c, r1)
    L1.append(d1)
    a += 1

a = 1
b = 1
c = 1
for x in range(i):
    r2 = math.gcd(a, b)
    d2 = math.gcd(c, r2)
    L2.append(d2)
    b += 1

a = 1
b = 1
c = 1
for x in range(i):
    r3 = math.gcd(a, b)
    d3 = math.gcd(c, r3)
    L3.append(d3)
    c += 1

a = 1
b = 1
c = 1
for x in range(i):
    r4 = math.gcd(a, b)
    d4 = math.gcd(c, r4)
    L4.append(d4)
    a += 1
    b += 1

a = 1
b = 1
c = 1
for x in range(i):
    r5 = math.gcd(a, b)
    d5 = math.gcd(c, r5)
    L5.append(d5)
    a += 1
    c += 1

a = 1
b = 1
c = 1
for x in range(i):
    r6 = math.gcd(a, b)
    d6 = math.gcd(c, r6)
    L6.append(d6)
    b += 1
    c += 1

a = 1
b = 1
c = 1
for x in range(i):
    r7 = math.gcd(a, b)
    d7 = math.gcd(c, r7)
    L7.append(d7)
    a += 1
    b += 1
    c += 1

G1 = sum(L1)
G2 = sum(L2)
G3 = sum(L3)
G4 = sum(L4)
G5 = sum(L5)
G6 = sum(L6)
G7 = sum(L7)

G = G1 + G2+G3+G4+G5+G6+G7
T = G - 6
print(T)

Submission status: Wrong Answer

Solution code:
gcd = [1,1,1]
k = int(input())
summary = 1

for _ in range(k-1):
  gcd[0] = gcd[0] + 1
  for _ in range(k-1):
    gcd[1] = gcd[1] + 1
    for _ in range(k-1):
      gcd[2] = gcd[2] + 1
      mg = 0
      for i in range(max(gcd)):
        if gcd[0]%(i+1) == 0 and gcd[1]%(i+1)==0 and gcd[2]%(i+1)==0:
          mg = i + 1
      summary += mg
      
print(summary)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

def main():
    n = int(input())
    result = 0
    
    for i in range(2,n+1):
        for j in range(2,n+1):
            for l in range(2,n+1):
                result += gcd(i,j,l)
    
    result += 1 + (n-1)*6
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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):
            if (a%b==0 or b%a==0) and (b%c==0 or c%b==0) and (c%a==0 or a%c==0):
                total += 1
            else:
                total += gcd(a,b,c)
print (total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
tmp = 0
for i in range(1,N+1):
	for n in range(1,N+1):
		for p in range(1,N+1):
			if i < n:
				tmp = i
				i = n
				n = tmp
			r = i % n
			while not r==0:
				i = n
				n = r
				r = i % n
			if n < p:
				tmp = n
				n = p
				p = tmp
			r = n % p
			while not r==0:
				n = p
				p = r
				r = n % p
			ans.append(p)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

import math
from functools import reduce


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

def g(num):
    cul = 0
    if num == 1:
        return 1
    
    new = num + 1
    for X in range(1, new):
        for Y in range(1, new):
            for Z in range(1, new):
                cul += gcd(X, Y, Z)
                
    
    return cul

g(n)

Submission status: Wrong Answer

Solution code:
import fractions

from functools import reduce
K=int(input())

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


count=0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      """
      if i==j and j==k and k==i:
        n=1
      elif i==j or j==k or k==i:
        n=3
      else:
        n=6
      """
      count+=gcd_list([i,j,k])

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
k = int(input())

a = 0
for i in range(k):
  for j in range(k):
    for l in range(k):
      a +=np.gcd.reduce([i,j,l]) 
print(a)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import math
import fractions
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

k = I()

result = 0

gcdList = {}

frc = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        t = (i,j)
        if t in gcdList:
            frc = gcdList[t]
        else:
            frc = fractions.gcd(i,j)
            gcdList[t] = frc
            
        for l in range(1, k+1):
            t2 = (gcdList[(i,j)],l)
            
            if t2 in gcdList:
                frc = gcdList[t2]
            else:
                frc = fractions.gcd(frc,l)
                gcdList[t2] = frc
            
            result += frc

print(result)

Submission status: Wrong Answer

Solution code:
import scipy as sp
from itertools import  combinations_with_replacement as com

def tri_gcd(a, b, c):
    return sp.gcd(a,  sp.gcd(b, c))

def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return set(divisors)

N = int(input())
ans = 0
duplication = 1
count_for = 0
for a in range(N+1):
    for b in make_divisors(a):
        for c in make_divisors(b):
            if len(set([a,b,c])) == 3:
                duplication = 6
            if len(set([a,b,c])) == 2:
                duplication = 3
            if len(set([a,b,c])) == 1:
                duplication = 1
            ans += duplication * tri_gcd(a, b, c)
            print(a,b,c)
            count_for += 1
print(ans)

Submission status: Wrong Answer

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):
            if (a != b) and (b != c) and (c != a):
                total += 1
            else:
                total += gcd(a,b,c)
print (total)

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)

import itertools
a=int(input())
A=[]
for i in range(a):
    A.extend(str(i+1))

li=list(itertools.combinations_with_replacement(A, 3))
s = 0
for lis in li:
    a = int(lis[0])
    b = int(lis[1])
    c = int(lis[2])
    
    gcd1 = gcd(a,b,c)
    
    if a==b and b==c:
        s = s + gcd1
    elif a==b or b==c:
        s = s + 3*gcd1
    else:
        s = s + 6*gcd1
print(s)

Submission status: Wrong Answer

Solution code:
import itertools
from fractions import gcd
 
K = int(input())
l = range(1, K+1)
ans = 0
 
for a, b, c in itertools.combinations_with_replacement(l, 3):
    print(a, b ,c)
    if a == b and b == c:
        ans += a
    elif a == b or b ==c:
        ans += gcd(a, c) * 3
    else:
        ans += gcd(gcd(a, b), c) *6
        
 
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint
from fractions import gcd

import math
from functools import reduce

memo = {}
def mygcd(a, b):
    fixed = (a,b)
    if fixed in memo:
        # print("in memo")
        return memo[fixed]
    memo[fixed] = gcd(a,b)
    return memo[fixed]

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

def gcd_list(numbers):
    return reduce(mygcd, numbers)

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

p_set = set()
tmp = primes(K)
p_set = set(tmp)
p_set.add(1)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            if a in p_set or b in p_set or c in p_set:
                ans += 1
            else:
                nums = [a, b, c]
                nums.sort()
                ans += gcd_list(nums)

print(ans)

Submission status: Wrong Answer

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

s = int(input())
qwe = np.arange(s+1)

sum = (1+s)*s/2

for i in range(1, s+1):
    for j in range(i + 1, s+1):
        sum += gcd(i, j, j) * 3
        sum += gcd(i, i, j )* 3
        for k in range(j + 1, s+1):
            sum += gcd(i, j, k)
print(int(sum))

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import itertools


k = int(input())
tot = 0

# 二つの数のgcdを計算した結果を入れる配列
g = np.array([[-1] * (k + 1)] * (k + 1), dtype=np.int64)

for l, m, n in itertools.product(range(k + 1), range(k + 1), range(k + 1)):
    if g[l][m] == -1:
        g[l][m] = math.gcd(l, m)
    lm_gcd = g[l][m]

    if g[lm_gcd][n] == -1:
        g[lm_gcd][n] = math.gcd(lm_gcd, n)
    tot += g[lm_gcd][n]
    
print(tot)

Submission status: Wrong Answer

Solution code:
import math
K=int(input())
GCD=[[0]*(K+2) for _ in range(K+2)]

def divable(a,b):
    if a==b:
        return a
    if a<b:
        a,b=b,a
    if a%b>0:
        return 1
    return math.gcd(a,b)

def make_GCD(K):
    for a in range(1,K+1):
        for b in range(1,K+1):
            GCD[a][b]=divable(a,b)
def gcd3(a,b,c):
    if a<b:
        a,b=b,a
    a=GCD[a][b]
    if a<c:
        a,c=c,a
    return GCD[a][c]

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math

K = int(input())
dp = defaultdict(int)

def gcd(a,b):
  a,b = sorted([a,b])

  k = "".join([ str(x) for x in [a,b]])
  if not dp[k]:
    # dp[k] = F(a,b)
    dp[k] = math.gcd(a,b)

  return dp[k]

tmp = []
for a in range(1, K+1):
  for b in range(1, K+1):
    k = "".join([ str(x) for x in sorted([a,b])])

    if not dp[k]:
      dp[k] = gcd(a,b)

    tmp.append(dp[k])

res = 0
for t in tmp:
  for c in range(1, K+1):
    k = "".join([ str(x) for x in sorted([t,c])])

    if not dp[k]:
      dp[k] = gcd(t,c)

    res += dp[k]

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input()) + 1


def find_gcd(x, y):
    while y:
        x, y = y, x % y

    return x


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

Submission status: Wrong Answer

Solution code:
k=int(input())
sumk=0
for i in range (1,k+1):
    for a in range(1,k+1):
        for b in range(1,k+1):
            for c in range(1,k+1):
                gcd=1
                m=min(a,b,c)
                for x in range(1,m+1):
                    if (a%x==0 and b%x==0 and c%x==0):
                        gcd=x
                    else:
                        gcd=gcd
                        sumk=sumk+gcd
print(sumk)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools
import numpy as np


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


K = int(input())

l = [i for i in range(1, K + 1)]

#temp_sum = np.array([])
#for j in itertools.combinations(l, 3):
#    print(j)
#    temp_sum=np.append(temp_sum,gcd_list(list(j)))

temp_1 = np.array([])

for i in l:
    for j in range(i+1,K+1):
        for k in range(j+1,K+1):
            print(i,j,k)
            temp_1 = np.append(temp_1, gcd_list([i, j, k]))

a=np.sum(temp_1)*6

temp_2 = np.array([])

for i in l:
    for j in range(i+1,K+1):
        temp_2 = np.append(temp_2, gcd_list([i, j, i]))
        temp_2 = np.append(temp_2, gcd_list([i, j, j]))

b=np.sum(temp_2)*3

temp_3 = np.array([])
for i in l:
    temp_3 = np.append(temp_3, gcd_list([i, i, i]))

print(int(np.sum(temp_3)+a+b))

Submission status: Wrong Answer

Solution code:
fizzBuzz = []
inputNumber = int(input())
for i in range(inputNumber + 1):
    if i % 3 == 0 and i % 5 == 0:
        metCondition = 'FizzBuzz'
    elif i % 5 == 0:
        metCondition = 'Buzz'
    elif i % 3 == 0:
        metCondition = 'Fizz'
    else:
        metCondition = i
    fizzBuzz.append(metCondition)
metCondition_2 = [num for num in fizzBuzz if isinstance(num, (int, float))]
print(sum(metCondition_2))

Submission status: Wrong Answer

Solution code:
def main():
    memo = {}

    def gcd(a, b):
        nonlocal memo

        if a <= b:
            a, b = b, a

        if (a, b) in memo:
            return memo[(a, b)]

        if b == 0:
            memo[(a, b)] = a
            return 0

        if b == 1:
            memo[(a, b)] = 1
            return 1

        memo[(a, b)] = gcd(b, a%b)
        return memo[(a, b)]

    k = int(input())

    s = 0

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

    print(s)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
x = range(2,n+1)
gcd = n**2 - n +1

for a in x:
    for b in x:
        for c in x:
                if a == b and b == c and c== a:
                    gcd += a
                elif a == b:
                    gcd += math.gcd(a, c)
                else:
                    gcd += math.gcd(math.gcd(a,b), c)
print(gcd)

Submission status: Wrong Answer

Solution code:
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x % y == 0:
    return y
  else:
    while x % y != 0:
      z = x % y
      x = y
      y = z
    else:
      return z
K = int(input())
x = 0
y = 0
z = 9
 
for i in range(3, K+1):
  for k in range(3, K+1):
    x = gcd(i,k)
    for j in range(3, K+1):
      y = gcd(x, j)
      z += y
print(z)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

K = int(input())
sum = 0
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            r = reduce(math.gcd,[a,b,c])
            if len(set([a,b,c]))==1:
                sum += r
            else:
                if K==2:
                    sum += r*3
                else:    
                    sum += r*math.factorial(K)
print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=n**3-n
b=0
for i in range(1,n+1):
  b=b+i
print(a+b)

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)

import itertools
a=int(input())
A=[]
for i in range(a):
    A.extend(str(i+1))

li=list(itertools.combinations_with_replacement(A, 3))
s = 0
for lis in li:
    a = int(lis[0])
    b = int(lis[1])
    c = int(lis[2])
    
    gcd1 = gcd(a,b,c)
    
    if a==b and b==c:
        s = s + gcd1
    elif a== b or b==c:
        s = s + 3*gcd1
    else:
        s = s + 9*gcd1
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(s)

def gcd( x, y, z ):
  # x > y > z
  lst = []
  lst.append(x)
  lst.append(y)
  lst.append(z)
  lst.sort()
  #print(lst)
  wk = yc(lst[0],lst[2])
  return yc(wk,lst[1])
  
def yc( a, b ) :
  if a == b :
    return a
  # a>=b 前提
  if a < b :
    z = a
    b = a
    a = z

  m = a % b
  if m == 0 :
    res = b
  else:
    res = yc(b, m )
  return res

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

print(sum)

Submission status: Wrong Answer

Solution code:
k = int(input())

ans = [1,10,40,116,257,524,924,1548,2433,3682,5272,7480,10169,13580,17828,23076,29157,36642,45172,55420,67309,80996,96224,114212,134265,156834,182076,210664,241717,277180,315464,358004,404585,455478,510840,572664,638521,709768,786652,871040,960389,1058270,1161612,1273140,1393281,1521328,1655908,1802224,1956401,2121218,2295656,2481492,2675649,2883576,3102388,3335656,3580933,3838790,4106972,4395188,4694445,5008080,5338284,5686120,6049093,6432802,6829844,7246292,7680317,8137284,8609232,9108972,9624553,10160626,10720384,11304344,11909177,12542828,13195044,13878756,14587821,15322054,16076788,16869976,17688893,18535496,19410008,20319504,21252585,22229730,23235856,24277360,25350745,26457212,27595748,28782860,29998005,31253106,32548248,33891100,35264353,36686548,38140364,39642740,41196101,42791538,44421108,46112400,47839117,49621228,51448720,53336492,55262345,57249182,59282856,61372632,63517965,65715448,67962088,70294192,72673277,75108110,77598644,80153244,82762869,85456788,88198840,91012828,93888073,96840158,99843464,102939488,106096737,109321248,112627488,116016064,119460673,122994310,126585632,130279556,134046641,137889264,141801588,145829472,149931565,154113514,158383936,162745484,167173337,171721340,176337444,181056084,185868873,190787434,195790720,200922568,206128049,211427060,216819068,222340452,227951157,233690166,239508556,245438752,251491645,257647784,263887256,270289976,276783657,283407510,290148588,297012604,303966061,311060512,318275528,325635464,333110609,340704474,348394104,356280348,364264513,372395260,380649148,389052596,397576493,406261346,415064172,424013784,433119321,442386916,451763572,461338276,471024341,480851438,490848572,501023352,511314165,521807532,532419304,543232996]

print(ans[k-1])

Submission status: Wrong Answer

Solution code:
K = int(input())
ans = 0
K -= 2
m = K // 3
ans += (2 * m) + ((2 + m + 1) * m / 2)
if K%3 == 0:
    print(ans + 1 + K)
elif K%3 == 1:
    print(ans + 1 + K + 1)
else:
    print(ans + 1 + K + 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
box = []
for i in range(1,k+1):
  for j in range(1,k+1):
    gap = math.gcd(i,j)
    if gap == 1:
      box.append(1*k)
    else:
      for l in range(1,k+1):
        gap2 = math.gcd(gap,l)
        box.append(gap2)        
print(sum(box))
print(box)

Submission status: Wrong Answer

Solution code:
import itertools
import math
a=int(input())
l=[i for i in range(1,a+1)]
l1=l*2
k=0
p=itertools.combinations_with_replacement(l1,3)
p=set(p)
for j in p:
    m=math.gcd(j[0],math.gcd(j[1],j[2]))
    k+=m
print(k)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop
import math

INF = float('inf')
NIL = - 1

import time
from functools import wraps


def stop_watch(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        start = time.time()
        result = func(*args, **kwargs)
        elapsed_time = time.time() - start
        print(f'{elapsed_time} [ms]')
        return result

    return wrapper


def gcd(a, b):
    """
    Greatest Common Divisor
    Euclidean Algortihm
    """
    if a < b:
        gcd(b, a)
    while b != 0:
        a, b = b, a % b
    return a


def is_prime(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True


@stop_watch
def main():
    K = int(input())
    num_list = range(1, K + 1)

    total = 0

    for a in range(1, K + 1):
        if a == 1:
            total += K ** 2
            continue
        for b in range(1, K + 1):
            if b == 1:
                total += K
                continue
            tmp = gcd(a, b)
            if tmp == 1:
                total += K
                continue
            tmp_b = is_prime(tmp)
            for c in range(1, K + 1):
                if c == 1:
                    total += 1
                    continue
                if tmp_b:
                    if c % tmp == 0:
                        total += tmp
                        continue
                    else:
                        total += 1
                        continue
                else:

                # print(a, b, c)
                # print(gcd(tmp, c))
                    total += gcd(tmp, c)
    print(total)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())

def gcd(a, b, c):
    min = a
    if b < min:
        mid = min
        min = b
    else:
        mid = b
    if c < min:
        max = mid
        mid = min
        min = c
    else:
        if c < mid:
            max = mid
            mid = c
        else:
            max = c
    if mid % min == 0 and max % min == 0:
        return min
    else:
        m = mid - min
        if (max - mid > 0 and max - mid < m) or m == 0:
            m = max - mid
        return gcd(m, min, mid)


sum = 1
for i in range(2, k+1):
    sum_i = 0
    sum_i += k
    for j in range(1, k):
        sum_i += gcd(k, j, j) * 6
    for j in range(2, k):
        for l in range(1, j):
            sum_i += gcd(k, j, l) * 6
    sum += sum_i
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
from itertools import *
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
 
K = int(input())
ans = 0
seq = [i for i in range(1,K+1)]
s = sum(seq)
seq = list(combinations_with_replacement(seq,3))
for a,b,c in seq:
  if a == b and b == c:
    continue
  ans += gcd(a,b,c)

print(ans*3+s)

Submission status: Wrong Answer

Solution code:
n = int(input())

import math
from functools import reduce


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

def g(num):
    cul = 0
    if num == 1:
        return 1
    
    for X in range(num):
        for Y in range(num):
            for Z in range(num):
                cul += gcd(X, Y, Z)
    cul += g(num-1)
    return cul

g(n)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

_sum = 0

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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


x=int(input())
sum=0
l=0
k=0
h=1

for l in range(x):
    l=l+1
    for k in range(x):
      k=k+1
      for h in range(x):
          sum=sum+gcd(l,k,h)
print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce


dic = {}
ans = 0
n = int(input())
for i in range(n):
    for j in range(n):
        for k in range(n):
            key=(i+1)*(j+1)*(k+1)
            if key in dic:
                ans = ans+dic[key]
            else:
                val = math.gcd(math.gcd(i+1, j+1), k+1)
                dic[key] = val
                ans = ans + val
print(ans)