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:
n=int(input())
s=1
for a in range(n):
    for b in range(n):
        for c in range(n):
            for i in range(n):
                if i==0:
                    continue
                if a%i==0 and b%i==0 and c%i==0:
                    g = i
                s+=g

print(s)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

_sum = 0
_sum = sum([i for i in range(1, K)])
_sum += sum([sum([math.gcd(i, j)*6 for i in range(j+1, K)]) for j in range(1, K)])

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

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)*6
print(_sum)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction as gcd
k = int(input())+1
out = 0
for i in range(1,k):
    for i2 in range(1,k):
        a = gcd(i,i2)
        for i3 in range(1,k):
            out += gcd(a,i3)
print(out)

Submission status: Wrong Answer

Solution code:
import math
k=200
s=0
for p in range(k):
  for q in range(k):
    g=math.gcd(p+1,q+1)
    for i in range(k):
      r=math.gcd(g,i+1)
      s=s+r
print(s)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

def gcd_3(a,b,c):
    p = gcd(a,b)
    q = gcd(p,c)
    return q

k = int(input())
ans = 0

num = list(itertools.combinations_with_replacement(range(1,k+1),3))

for l in num:
    a,b,c = l
    if a==b==c:
        ans += a
    else:
        ans += gcd_3(a,b,c)*3
print(ans)

Submission status: Wrong Answer

Solution code:
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])
    
    for i in range(min(a,b,c)):
        if a%(i+1) == 0 and b%(i+1) == 0 and c%(i+1) ==0:
            gcd = i+1
            if a==b and b==c:
                s = s + gcd
            elif a== b or b==c:
                s = s + 3*gcd
            else:
                s = s + 9*gcd
print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 22:01:05 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):
        gcd_a_b = math.gcd(a, b)
        for c in range(1, K+1):
            answer += math.gcd(gcd_a_b, c)
print(answer)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

k = int(input())

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

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

lst = []
for i in range(2):
    a = i + 1
    for j in range(2):
        b = j + 1
        for l in range(2):
            c = l + 1
            koyakusu = gcd(a, b, c)
            lst.append(koyakusu)
kotae = sum(lst)
print(kotae)

Submission status: Wrong Answer

Solution code:
def gcd2(a,b):
    x, y = max(a, b), min(a, b)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            x, y = y, x % y
        return x


K = int(input())
s = [gcd2(a, b) for a in range(1, K+1) for b in range(a+1, K+1)]
t = [2 * gcd2(a, b) for a in range(1, K+1) for b in s]
n = [gcd2(a, b) for a in range(1, K+1) for b in range(1, K+1)]
print(sum(t)+sum(n))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions

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

cnt = 0
for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k) * 3
            if i == j:
                if j == k:
                    #print('ok')
                    b = int(b/3)
            #print(str(i) + ' ' + str(j) + ' ' + str(k) + ' : ' + str(b))
            cnt += b

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

K = int(input())
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

K = int(input())
tmp = []

c = 0
for i in range(K):
    for j in range(K):
        tmp.append(math.gcd(i + 1, j + 1))
        c = c + 1

tmp2 = []
for k in tmp:
    for m in range(K):
        tmp2.append(math.gcd(k, m+1))

print("sum:",sum(tmp2))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

N = int(input())
n = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            n += gcd(i,j,k)
print(n)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

K = int(input())

sum1 = 0
sum2 = 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 <= k:
                sum1 += gcd(i, j, k)
            if i == j == k:
                sum2 += gcd(i, j, k)

print(sum1 * 3 - sum2 * 2)

Submission status: Wrong Answer

Solution code:
import time
t1 = time.time()

import math
import itertools
from functools import reduce

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

K = int(input())

ans = 0
for lst in itertools.combinations_with_replacement([i + 1 for i in range(K)], 3):
    ans += int(6 / math.factorial(4 - len(set(lst)))) * gcd(list(lst))

print(ans)

t2 = time.time()
print(t2 - t1)

Submission status: Wrong Answer

Solution code:
def compute_gcm(x, y):
  if x == y:
    return x
  if x < y:
    s = x
    x = y
    y = s
  if x==1:
    return 1
  a = x%y
  if a == 0:
    return y
  return compute_gcm(y, a)

print(compute_gcm(4,compute_gcm(2,2)))
k = int(input())
res = k**3-(k-1)**3
same1 = 0
same2 = 0
rate = [6,3,1]
for p in range(2,k+1):
  for q in range(p, k+1):
    same1 = int(p==q)
    gcm1 = compute_gcm(q,p)
    for r in range(q, k+1):
      same2 = int(q==r)
      gcm = compute_gcm(r,gcm1)
      res += gcm*rate[same1+same2]
      #print("p:{}, q:{}, r:{}, gcm:{}, rate:{}, sum:{}".format(p,q,r,gcm,rate[same1+same2],res))
print(res)

Submission status: Wrong Answer

Solution code:
import math
S = int(input())
n = 0
for i in range(S):
    for j in range(S):
        for k in range(S):
            a = math.gcd(i, j)
            b = math.gcd(a, k)
            n += b

print(int(n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import itertools
k = int(input()) 
l = list(range(1, k + 1))
ans = 0
for v in itertools.product(l, repeat=3):
    ans += min(list(v))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))




d = dict()
d2 = dict()

def check(a, b, d2):
    t = tuple(sorted([a,b]))
    if t in d2:
        return d2[t]
    return False

k = load()
s = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1, k+1):
            r = check(i, j, d2)
            target = None
            if r:
                target = k
            else:
                r = check(j, k, d2)
                if r:
                    target = i
                else:
                    r = check(i, k, d2)
                    if r:
                        target = j
                    else:
                        print(i,j,k)
                        d2[(i,j)] = gcd(i,j)
                        r = d2[(i,j)]
                        target = k
            r2 = check(r, target, d2)
            if r2:
                s += r2
            else:
                d2[(r, target)] = gcd(r, target)
                s += d2[(r, target)]

print(s)

Submission status: Wrong Answer

Solution code:
a=int(input())
sum=0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      if i%i==0 and j%i==0 and k%i==0:
        sum+=i
      else:
        sum+=1
print(sum,end="")

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

N = int(input())
n = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            n += gcd(i,j,k)
print(n)

Submission status: Wrong Answer

Solution code:
k = int(input())
from math import sqrt, ceil
def f(x):
  return (k//x)**3
def p(x):
  primes = []
  for i in range(2,x+1):
    while x % i == 0:
      x //= i
      primes.append(i)
    if x == 1:
      break
  return primes

ans = f(1)
for j in range(2, k+1):
  primes = p(j)
  ans += (j - j//primes[0])*f(j)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

k = int(input())
ans = 0

for i in range(1, k+1, 1):
    ans += i
    for l in range(i+1, k+1, 1):
        ans += (6 * gcd(i,l))
        for m in range(l+1, k+1, 1):
            ans += (3 * gcd(i,l,m))

print(ans)

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

Submission status: Wrong Answer

Solution code:
import fractions
K = int(input())
sum = 0
D = {}
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            if not (a+b+c in D) :
               D[a+b+c] = fractions.gcd(fractions.gcd(a,b),c)
            sum += D[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)

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

k = int(input())
output = 0
for i in range(k):
  for j in range(k):
    for h in range(k):
      output += gcd(i,j,h)
print(output)

Submission status: Wrong Answer

Solution code:
from math import gcd
k=200
ans=0
for i in range(1,k+1):
    for j in range(i,k+1):
        for k in range(j,k+1):
            s=len(set([i,j,k]))
            if s==1:
                p=1
            elif s==2:
                p=3
            elif s==3:
                p=6
            tmp=gcd(i,j)
            tmp= p*gcd(tmp,k)
            ans+=tmp
print(ans)

Submission status: Wrong Answer

Solution code:

import fractions
import math
k = int(input())
l = []

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:
                pass
            else:
                tmp = [i,j,k]
                ans = tmp[0]
                for m in range(1,3):
                    ans = fractions.gcd(ans, tmp[m])
#                print(i,j,k)
#                print(ans)
                l.append(ans)

x = sum(l) * 3
t = []
for i in range(1,k+1):
    t.append(i)
y = sum(t)


print(x+y)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

K = int(input())
result = 0

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

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

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import itertools
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]
num_list=[(x) for x in range(1,K+1)]

c_list = tuple(itertools.product(num_list,num_list,num_list))
c_list = list(map(list, (map(lambda x:sorted(x), c_list))))
c_list = list(map(list, set(map(tuple, c_list))))
ans=0
for i,j,k in c_list:
    I=gcd(i,j)
    I=gcd(I,k)
    if i==j:
        if j==k:
            ans+=I
        else:
            ans+=I*3
    elif j==k:
        ans += I * 3
    else:ans+=I*4
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

import math
from functools import reduce
import itertools

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
c = 0
  
for i,j,k in itertools.combinations_with_replacement(range(1,n+1), 3):
      c += gcd(i,j,k)
      
print(c)

Submission status: Wrong Answer

Solution code:
import math
import itertools
from functools import reduce

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

K = int(input())

ans = 0
three = math.factorial(3)
for lst in itertools.combinations_with_replacement([i + 1 for i in range(K)], 3):
    ans += three / math.factorial(4 - len(set(lst))) * gcd(list(lst))

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
num = int(input())
sum = 0
for i in range(1, num+1):
  for j in range(1, num+1):
    for k in range(1, num+1):
      if i > j or j > k:
        continue;
      else:
        temp = fractions.gcd(i, j)
        sum += fractions.gcd(temp, k)
print(sum)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

K = int(input())

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

Submission status: Wrong Answer

Solution code:
import math
K = 200
ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    tmp = math.gcd(i,j)
    for k in range(1,K+1):
      if tmp==1:
        ans += 1
      else:
        ans += math.gcd(tmp,k)
print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
sum=0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      if i%i==0 and i%j==0 and i%k==0:
        sum+=i
print(sum,end="")

Submission status: Wrong Answer

Solution code:
from math import gcd
from itertools import permutations

k = int(input())
ans = 0

for i in range(1, k+1):
    for j in range(i, k+1):
        for l in range(j, k+1):
            dup = len(set([i, j, l]))
            if dup == 1:
                num = 1
            elif dup == 2:
                num = len(list(permutations([i, j, l]))) / 2
            else:
                num = len(list(permutations([i, j, l])))
            ans += gcd(i, gcd(j, l)) * num

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

Submission status: Wrong Answer

Solution code:
from math import gcd

k = int(input())

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

print(result)

Submission status: Wrong Answer

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

def gcd( x, y, z ):
  # x > y > z
  lst = [ x,y,z].sort()
  #print(lst)
  wk = yc(x,z)
  return yc(wk,y)
  
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:
def compute_gcm(x, y):
  if x == y:
    return x
  if x < y:
    s = x
    x = y
    y = s
  if x==1:
    return 1
  a = x%y
  if a == 0:
    return y
  return compute_gcm(y, a)

k = int(input())
res = 0
same1 = 0
same2 = 0
rate = [6,3,1]
for p in range(1,k+1):
  for q in range(p, k+1):
    same1 = int(p==q)
    gcm = compute_gcm(q,p)
    for r in range(q, k+1):
      same2 = int(q==r)
      gcm = compute_gcm(r,gcm)
      res += gcm*rate[same1+same2]
      #print("p:{}, q:{}, r:{}, gcm:{}, rate:{}, sum:{}".format(p,q,r,gcm,rate[same1+same2],res))
print(res)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools
 

def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
 
x = int(input())
_sum = [gcd(*i) for i in itertools.product(range(x), repeat=3)]
print(sum(_sum))

Submission status: Wrong Answer

Solution code:
import math

# input
K = int(input())

# process
gcdl = []
for i in range(K):
    l = []
    for j in range(K):
        l.append(math.gcd(i+1, j+1))
    gcdl.append(l)
print(gcdl)

ans = 0
for a in range(K):
    for b in range(a, K):
        for c in range(b, K):
            print([a, b, c])
            if a == c:
                ans += a+1
            elif b == c:
                ans += gcdl[a][b]*3
            elif a == b:
                ans += gcdl[a][c]*3
            else:
                t = gcdl[a][b]
                t = gcdl[t-1][c]
                ans += t*6

# output
print(ans)

Submission status: Wrong Answer

Solution code:

import fractions
from functools import reduce


k = int(input())

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

k += 1
ans = 0

#for i in range(1,k):
#    for j in range(i,k):
#        #print(i,j)
#        if i == j:
#            ans += gcd(i,j)
#        else:
#            ans += gcd(i,j)*6

for i in range(1,k):
    for j in range((i+1),k):
        for h in range((j+1),k):
            #print(i,j,h)
            ans += gcd(i,j,h)*6


print(ans)

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):
    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)
        
 
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(i,k+1):
        for l in range(j,k+1):
            if i==j and j==l:
                ans+=i
#                 print(i,j,l)
                
                
            elif i==j or j==k:
                ans+=3*math.gcd(i,l)
#                 print(i,j,l)
                
                
            else:
                ans+=6*math.gcd(math.gcd(i,j),l)
#                 print(i,j,l)
                
                
            
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

k = int(input())

result = 0

for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      n = gcd(a, b)
      m = gcd(n, c)
      result += n

print(result)

Submission status: Wrong Answer

Solution code:
def main():
  k = int(input())
  params = [1,1,0]
  count = 0
  while params[0] < k or params[1] < k or params[2] < k:
    if params[2] < k:
      params[2] = params[2]+1
    elif params[1] < k:
      params = [params[0],params[1]+1,1]
    elif params[0] < k:
      params = [params[0]+1,1,1]
      
      tmp = gcd(params[0], params[1])
      count += 1 if tmp == 1 else gcd(tmp,params[2])
    
  return count

def gcd(val1, val2):
  return val1 if (val2 == 0) else gcd(val2, val1 % val2)
    
print(main())

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())
    sum_gcd = 0
    for i in range(N**3):
        c = i%N
        b = i//N%N
        a = i//N//N%N
        sum_gcd += gcd(a+1,b+1,c+1)
        print(gcd(a+1,b+1,c+1))
    print(sum_gcd)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = int(input())
l = []
def gcd(n, m):
    if m == 0:
        return n
    else:
        return gcd(m, n%m)
    for n in range(1, a+1):
        for m in range(a+1):
            for p in range(1, a+1):
                ans = gcd(n, gcd(m, p))
                l.append(ans)
print(sum(l))

Submission status: Wrong Answer

Solution code:
import sys
import math
#import fractions
from functools import reduce
import itertools

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

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


N = II()
l = []
for i in range(1,N+1):
    l.append(i)
ans=0

num = 3 #生成するビット数
bit_list = list(itertools.product(l, repeat=num))

#for L in bit_list:
#    ans += gcd_list(L)

print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math
import itertools

if __name__ == "__main__":
    K = int(input())+1
    ret = 0
    for a, b, c in itertools.product(range(1,K), range(1,K), range(1,K)):
        print("%d,%d,%d" % (a,b,c))
        ret += reduce(math.gcd, [a,b,c])
    print(ret)

Submission status: Wrong Answer

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

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

print( sum )

Submission status: Wrong Answer

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

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

def gcd_list(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):
            #print(a, b, c)
            ans+=gcd(a, b, c)
ans

Submission status: Wrong Answer

Solution code:
from functools import reduce
from math import gcd


k = int(input())
l = range(1, k+1)
s = 0

for a in l:
    for b in l:
        for c in l:
            l = [a, b, c]
            g = reduce(gcd, l)
            s += g
            
print(s)

Submission status: Wrong Answer

Solution code:
k = int(input())

import math
ans = sum(list(range(k+1)))
ans1 = 0
ans2 = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans1 += math.gcd(i,j)

ans = ans + ans1*3

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

ans += ans2*6
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce


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


k = int(input()) + 1

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

Submission status: Wrong Answer

Solution code:
import math
import itertools
import numpy as np
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
list2 = []
result = 0
n = int(input())
for i in range(1,n+1):
    if(not(is_prime(i))):
        for j in range(1,n+1):
          for k in range(1,n+1):
#            list2.append([i,j,k])
            result +=  np.gcd.reduce((i,j,k))
#            print(result ,i,k,j)
    else:
        result += n*n-1
for i in range(1,n+1):
    if(is_prime(i)):
        result += i
print(result)
#print(list2)

Submission status: Wrong Answer

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

def reduce_gcd(x,y,z):
    return reduce(euclid,(x,y,z))

def main():
    from functools import reduce
    K=int(input())
    ans=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            for c in range(1,K+1):
                ans+=reduce_gcd(a,b,c)

main()

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce
K = int(input())
def gcd_List(List):
  return reduce(gcd,List)
sum = 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 and k != i:
        sum += gcd_List([i,j,k])
      elif i == j and i != k:
        sum += gcd(i,k)*3
      elif i == k and i != j:
        sum += gcd(i,j)*3
      elif j == k and i != j:
        sum += gcd(i,k)*3
      else:
        sum += i
print(sum)

Submission status: Wrong Answer

Solution code:
k = int(input())
import math
k1 = 0
k2 = 0
k3 = 0
count = 0
for i in range(0,k):
  k1 = k1 + 1
  k2 = 0
  for j in range(0,k1):
    k3=0
    k2 = k2 + 1
    for k in range(0, k2):
      k3 = k3 + 1
      if k1==k2==k3:
        count = count + k1
      elif k1==k2:
        count = count + 3*math.gcd(k1,k3)
      elif k2==k3:
        count = count + 3*math.gcd(k1,k2)
      elif k3==k1:
        count = count + 3*math.gcd(k1,k2)
      else:
        k4 = math.gcd(k1,k2)
        count = count + 6*math.gcd(k3,k4)
print(count)
print(k1,k2,k3)

Submission status: Wrong Answer

Solution code:
import math

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

k = int(input()) + 1
ans = 0
dp = []
for a in range(1, k):
    for b in range(a, k):
        for c in range(b, k):
            if (a, b, c) in dp: continue
            if a == b and b == c:
                ans += a
            elif a == b or b == c:
                a, b = set((a, b, c))
                ans += math.gcd(a, b) * 3
            else:
                ans += gcd(a, b, c) * 6
            dp.append((a, b, c))
print(ans)

Submission status: Wrong Answer

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


def gdc(x,y):
  result = 1
  for z in range(min(x,y)):
    if x%(z+1)==0 and y%(1+z)==0:
      result *= (z+1)
  return result

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
k = int(input())
#3つとも違う数字
s3=0
for a in range(3,k+1):
    for b in range(2,k):
        for c in range(1,k-1):
            if c<b<a:
                s3+=gcd(gcd(b,c),a)
#2種類
s2 = 0
for a in range(2,k+1):
    for b in range(1,k):
        if b<a:
            s2+=gcd(a,b)
s = s3*6 + s2*6 +k*(k+1)/2
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

K = int(input())
ans = 0
memo = {}

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

Submission status: Wrong Answer

Solution code:
n = int(input())

def gcd(num):
    cul = 0
    for X in range(n+1):
        for Y in range(n+1):
            for Z in range(n+1):
                if (Y+1) % (Z+1) == 0:
                    cul += min(Y, Z)
                    next
                elif (Z+1) % (X+1) == 0:
                    cul += min(Z, X)
                    next
                elif (X+1) % (Y+1) == 0:
                    cul += min(X, Y)
                    next
                else:
                    cul += 1
    return cul


gcd(n)