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:
import math
k=int(input())

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

Submission status: Wrong Answer

Solution code:
import math

K = int(input())
sum = 0

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

Submission status: Wrong Answer

Solution code:
import math

K = int(input())
sum = 0

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

Submission status: Wrong Answer

Solution code:
import math

K = int(input())
sum = 0

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

Submission status: Wrong Answer

Solution code:
k = int(input())

def gcd(a,b,c):
  s = [a,b,c]
  s.sort()
  a,b,c = s
  for n in range(1,a+1):
    if a % n == 0 and b % n == 0 and c % n == 0:
      yakusu = n
  return n

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

Submission status: Wrong Answer

Solution code:
from math import gcd

K = int(input())
ans_list = list()
"""
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a % b)
"""
for X in range(1, K+1):
    ans = 0
    for i in range(1, X+1):
        for j in range(1, X+1):
            tmp = gcd(i, j)
            if tmp == 1:
                ans += tmp*X
            else:
                for k in range(1, X+1):
                    ans += gcd(tmp, k)
                
    print(X, ans)
    ans_list.append(ans)
        
print(ans_list)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:


from math import gcd as g


k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(k+1):
        temp = g(a, b)
        for c in range(k+1):
            ans += g(temp, c)


print(ans)

Submission status: Wrong Answer

Solution code:


import math
rst = 0
K = int(input())
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):
            rst += math.gcd(k, tmp)
            print(rst)

Submission status: Wrong Answer

Solution code:


from math import gcd as g

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(k+1):
        for c in range(k+1):
            ans += g(g(a, b), c)


print(ans)

Submission status: Wrong Answer

Solution code:


def gcd(p, q):
    if q == 0:
        return p
    else:
        return gcd(q, p % q)


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


print(ans)

Submission status: Wrong Answer

Solution code:

import math

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


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import gcd
import itertools
n = int(input())
ans = 0

for C in itertools.combinations_with_replacement(range(1,n+1),3):
    ans += gcd(gcd(C[0],C[1]),C[2])
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            check=[i,j,k]
            first = check[0]
            for i in range(3):
                first = math.gcd(first, check[i])
                ans+=first
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
def main():
    N = int(input())

    ans = 0
    for i in range(N + 1):
        if i % 3 != 0 and i % 5 != 0:
            ans += i
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())
s = 0


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


for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            a, b, c = sorted([i, j, k])
            s += gcd(a, gcd(b, c))

print(s)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import functools

K = int(input())

ans = 0

for i in itertools.product(range(1,K+1),repeat=3):
    ans += functools.reduce(math.gcd,i)
    print(i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [1, 3, 6]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    print(time.time() - s)

Submission status: Wrong Answer

Solution code:
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [6, 3, 1]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    # print(time.time() - s)

Submission status: Wrong Answer

Solution code:
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [6, 3, 1]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    print(time.time() - s)

Submission status: Wrong Answer

Solution code:
k=int(input())
n=0
for a in range(k):
    a+=1
    for b in range(k):
        b+=1
        for c in range(k):
            c+=1
            s=1
            for d in range(k):
                d+=1
                if a>=d and b>=d and c>=d and a%d == 0 and b%d== 0 and c%d == 0:
                    s=s*d
            n+=s
print(n)

Submission status: Wrong Answer

Solution code:
k = int(input())

ans = 0
for i in range(1, k + 1):
    for j in range(1, i + 1):
        for l in range(1, j + 1):
            while True:
                p = i
                q = j
                r = p % q
                p = q
                q = r
                if q == 0:
                    break
                q = l
                r = p % q
                p = q
                q = r
                if q == 0:
                    ans += p
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())

ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        for l in range(k + 1):
            for m in range(k, 0, -1):
                if i % m == 0 and j % m == 0 and l % m == 0:
                    ans += m
                    
print(ans)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:48:51 2020

@author: Aruto Hosaka
"""


import math

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

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
gcd3 = 0
for a in range(1,K-1):
    for b in range(a+1,K):
        for c in range(b+1,K+1):
            gcd3 += math.gcd(math.gcd(a,b),c)
gcd2 = 0
for a in range(1,K):
    for b in range(a+1,K+1):
        gcd2 += math.gcd(a,b)
ans = gcd3 * 6 + gcd2 * 3 + K*(K+1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())
ans = 0
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
for a in range(K):
    for b in range(K):
        for c in range(K):
            ans += gcd(gcd(a, b), c)
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 j in range(1, k + 1):
    for t in range(1, k + 1):
      ans += gcd(gcd(i, j), k)

print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())
l=list(range(1, k+1))
import itertools
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd, numbers)
ans=0
for v in itertools.combinations_with_replacement(l, 3):
  ans+=gcd(*v)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement

K = int(input())
k_range = list(range(1, K+1))

result = 0
for comb in combinations_with_replacement(k_range, 3):
    min_abc = min(comb)
    for i in range(min_abc, 0, -1):
        if (comb[0]%i == 0 and comb[1]%i == 0) and comb[2]%i == 0:
            if comb[0]==comb[1] and comb[1]==comb[2]:
                coef = 1
            else:
                coef = 3
            result += i * coef
            break
print(result)

Submission status: Wrong Answer

Solution code:
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):
            max_abc = max([a,b,c])
            print(a,b,c)
            for i in range(max_abc, 0, -1):
                if (a%i == 0 and b%i == 0) and c%i == 0:
                    result += i
                    break
print(result)

Submission status: Wrong Answer

Solution code:
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(input())
ans=0
for numbers in itertools.combinations_with_replacement(range(1,k+1),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    K = int(input())
    ans = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            for p in range(1, K+1):
                count = []
                for q in range(1, min(i, j, p)+1):
                    if i%q == 0 and j%q == 0 and p%q == 0:
                        count.append(q)
                ans.append(max(count))
    print(sum(ans))
resolve

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    ans = []
    for i in range(1, N+1):
        for j in range(1, N+1):
            for p in range(1, N+1):
                count = [1]
                for q in range(2, min(i, j, p)+1):
                    if i%q == 0 and j%q == 0 and p%q == 0:
                        count.append(q)
                ans.append(count[-1])
    print(sum(ans))
resolve

Submission status: Wrong Answer

Solution code:
import math

math.gcd(2,10)
N =int(input())
total = 0
a=1
b=1
c=1
if N ==1:
	total =1
while a <=N:
	b=1
	while b <=N:
		c=1
		while c <=N:
			if math.gcd(a,b)==1:
				total += N
				break
			total += math.gcd(a,math.gcd(b,c))
			c+=1
		b+=1 
	a+=1
print(total)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
result = 0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            result+=gcd(i,j,k)
print(result)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
result = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            result+=gcd(i,j,k)
result

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import gcd

k = int(input())
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())
from math import gcd
from itertools import permutations
l=[i for i in range(1,k+1)]
L=permutations(l,3)
s=0
for a,b,c in L:
   a=gcd(a,b)
   s+=gcd(a,c)*6
L=permutations(l,2)
for a,b in L:
    s+=gcd(a,b)*3
for k in l:
    s+=k
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())
count = 0
for i in range(1,K+1):
  for j in range(i+1,K+1):
    for k in range(j+1,K+1):
      count += 6*(gcd(i,j,k))
      
for i in range(1,K+1):
  for j in range(i+1,K+1):
    count += 3*(gcd(i,j))

for i in range(1,K+1):
  count += i
      
print(count)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
k = int(input())

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

ans = 0

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

for a in range(1,k+1):
    for b in range(1,k+1):
        if a!=b:
            ans += 3*gcd(a,a,b)

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 a!=c and b!=c:
                ans +=6*gcd(a,b,c)


print(ans)

Submission status: Wrong Answer

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


def gcd(a, b, c):
    ma = max(a, b, c)
    mi = min(a, b, c)
    for k in range(ma, mi, -1):
        if a % k == 0 and b % k == 0 and c % k == 0:
            return k
    return 1


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

print(ans)

Submission status: 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(ans)

Submission status: Wrong Answer

Solution code:
import fractions
su = 0
n = int(input())

def ggcd(i,j,k):
    ans = fractions.gcd(i,j)
    ans = fractions.gcd(ans, k)
    return ans
    
su = 1
su+=n**3-(n-1)**3
for i in range(n-1):
    for j in range(n-1):
        for k in range(n-1):
            su += ggcd(i+1,j+1,k+1)
print(su)

Submission status: Wrong Answer

Solution code:
from math import gcd

k = 200
total = 0
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, gcd(a, gcd(b, c)))
            total += gcd(a, gcd(b, c))
print(total)

Submission status: Wrong Answer

Solution code:
#C
def gcd(a, b):
    if b > a:
        a, b = b, a
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
        
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):
            tmp = gcd(a, b)
            ans += gcd(tmp, c)
print(ans)

Submission status: Wrong Answer

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

for a in range(1,K+1):
  for b in range(a+1,K+1):
    for c in range(b+1,K+1):
      total += math.gcd(a, math.gcd(b,c) )
total *= 6
for a in range(1,K+1):
  for b in range(a+1,K+1):
    total += math.gcd(a, b)
total *= 6


for a in range(1,K+1):
  total += a

print(total)

Submission status: Wrong Answer

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

for a in range(K):
  for b in range(a+1,K):
    for c in range(b+1,K):
      total += math.gcd(a+1, math.gcd(b+1,c+1) )
total *= 6
for a in range(K):
  for b in range(a+1,K):
    total += math.gcd(a+1, b+1)
total *= 6


for a in range(K):
  total += (a+1)

print(total)

Submission status: Wrong Answer

Solution code:
from itertools import product
from functools import reduce
# import math

def gcd(a, b):
  while b:
    a, b = b, a % b
    return b
  
def gcd_three(tup):
  return reduce(lambda a, b: gcd(a, b), tup)


K = int(input())
lst = range(1, K+1)
Sum = 0

for tup in product(lst, lst, lst):
  Sum += gcd_three(tup)
  
print(Sum)

Submission status: Wrong Answer

Solution code:
def gcd(p,q):
    if p%q == 0:
        return q
    return gcd(p,p%q)



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

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
b = 7/2*k*k - 5/2*k + 1
for i in range(2,k+1):
    for j in range(2,k+1):
        ij = math.gcd(i,j)
        for m in range(2,k+1):
            if i==k and i == m:
                continue
            b += math.gcd(ij,m)
print(int(b))

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
ans=0
for i in range(2,n+1):
    for j in range(1,n+1):
        ij=math.gcd(i,j)
        if ij==1:
            ans+=n
        else:
            for k in range(1,n+1):
                ans+=math.gcd(ij,k)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

K = 200 #int(input())

total = 0
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):
            total += math.gcd(ab, c)

print(total)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

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

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

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

Submission status: Wrong Answer

Solution code:
import math
#import itertools
num = (int)(input())
total = 0
#for i, j, k in itertools.product(list(range(1, num + 1)), list(range(1, num + 1)), list(range(1, num + 1))):
#  total += math.gcd(math.gcd(i, j), k)
#print(total)
for i in range(2, num + 1):
  for j in range(2, num + 1):
    for k in range(2, num + 1):
      total += math.gcd(math.gcd(i, j), k)
print(total)

Submission status: Wrong Answer

Solution code:
k = int(input())
sum = 0


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


for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            if a == b == c:
                sum += a
            elif a == b or b == c:
                sum += euclid(euclid(a, b), c) * 3
            else:
                sum += euclid(euclid(a, b), c) * 6
                print(sum)

Submission status: Wrong Answer

Solution code:
k = int(input())
sum = 0

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


for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            if a == b == c:
                sum += a
            elif a == b or b == c:
                sum += euclid(euclid(a,b), c) * 3
            else:
                sum += euclid(euclid(a,b), c)
print(sum)

Submission status: Wrong Answer

Solution code:
def gcd(a,b,c):
    gcd=0
    for i in range(1, a+1):
        if a%(a+1-i)==0 and b%(a+1-i)==0 and c%(a+1-i)==0:
            gcd=a+1-i
            break
    return gcd
def Sum(K):
    s=0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for l in range(1,K+1):
                s=s+gcd(i,j,l)
    return s
print(Sum(2))

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    x, y = sorted([x, y])
    g = 1
    for i in range(1, x+1):
        if y%i==0:
            g = i
    return g

k = int(input())

count_lst = [0] * k
for i in range(1, k+1):
    for j in range(1, k+1):
        g = gcd(i,j)
        count_lst[g-1] += 1

ans = 0
for i in range(1, k+1):
    count = count_lst[i-1]

    for j in range(1,k+1):
        g = gcd(i,j)
        ans += count * g

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, gcd
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
# from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

K = 200

ans = 0
for a, b, c in combinations_with_replacement(range(1, K+1), 3):
    # print(a, b, c)
    score = gcd(a,gcd(b,c))
    # print(score)
    l = len({a, b, c})
    # print(l)
    if l == 3:
        ans += score*6
    elif l == 2:
        ans += score*3
    else:
        ans += score

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
#from math import sqrt, ceil, floor, gcd
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

K = I()

ans = 0
ab = [[0]*(K+1) for _ in range(K+1)]
for a in range(1, K+1):
    for b in range(a, K+1):
        ab = gcd(a,b)
        for c in range(b, K+1):
            ans += gcd(ab, c)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import gcd

k = int(input())
num = 0

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

print(num)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())
num = 0

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

print(num)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

k = int(input())
sum = 0

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

print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

k = int(input())
sum = 0

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

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

print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

k = int(input())
sum = 0

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

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

print(sum)

Submission status: Wrong Answer

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


def better_gcd(a,b,c):
    tup = set((a,b,c))
    kinds = len(tup)
    if kinds == 3:
        return math.gcd(a, math.gcd(b, c)) * 6
    elif kinds == 2:
        return math.gcd(*tup) * 3
    else:
        return a

ans = 0
cands = list(itertools.combinations_with_replacement(range(1,201), 3))
for c in cands:
    ans += better_gcd(*c)
print(ans)

Submission status: Wrong Answer

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


def better_gcd(a,b,c):
    tup = set((a,b,c))
    kinds = len(tup)
    if kinds == 3:
        return math.gcd(a, math.gcd(b, c)) * 6
    elif kinds == 2:
        return math.gcd(*tup) * 3
    else:
        return a

ans = 0
cands = list(itertools.combinations_with_replacement(range(200), 3))
for c in cands:
    ans += better_gcd(*c)
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    # `a >= b` is sopposed
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def main():
    K = 200
    gcd_memo = [[0 for _ in range(K + 1)] for _ in range(K + 1)]
    for a in range(1, K + 1):
        for b in range(a, K + 1):
            left, right = max([a, b]), min([a, b])
            gcd_ab = gcd(left, right)
            gcd_memo[a][b] = gcd_ab
            gcd_memo[b][a] = gcd_ab
    answer = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            gcd_ab = gcd_memo[a][b]
            answer += sum(gcd_memo[gcd_ab])
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    # `a >= b` is sopposed
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def main():
    K = 200
    answer = 0
    for a in range(1, K + 1):
        for b in range(a, K + 1):
            gcd_ab = gcd(b, a)
            for c in range(b, K + 1):
                gcd_abc = gcd(c, gcd_ab)
                if a < b < c:
                    pattern_num = 6
                elif a == b < c or a < b == c:
                    pattern_num = 3
                else:
                    pattern_num = 1
                answer += pattern_num * gcd_abc
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())

K_list = [i+1 for i in range(K)]
gcd = sorted(K_list, reverse=True)[:-1]
res = 0
for l in range(len(gcd)):
  GCD = gcd[l]
  for i in range(len(K_list)):
    a = K_list[i]
    for j in range(len(K_list)):
      b = K_list[j]
      for k in range(len(K_list)):
        c = K_list[k]
        if a % GCD == 0 and b % GCD == 0 and c % GCD == 0:
          res += GCD
        elif 1 in [a, b, c]:
          res += 1
        
print(res)

Submission status: Wrong Answer

Solution code:
K = int(input())

K_list = [i+1 for i in range(K)]
gcd = sorted(K_list, reverse=True)[:-1]
res = 0
for l in range(len(gcd)):
  GCD = gcd[l]
  for i in range(len(K_list)):
    a = K_list[i]
    for j in range(len(K_list)):
      b = K_list[j]
      for k in range(len(K_list)):
        c = K_list[k]
        if 1 in [a, b, c]:
          res += 1
        elif a % GCD == 0 and b % GCD == 0 and c % GCD == 0:
          res += GCD
print(res)