Problem:


Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692



Sample input:
2


Sample output:
9

Submission status: Wrong Answer

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


memo = []
ans = 0
K = int(input())
for a in range(1, K+1):
    for b in range(1, K+1):
        memo.append(gcd(a,b))
memo.sort()
new_memo = list(set(memo))
for c in range(1, K + 1):
    ans += gcd(c, new_memo[c-1]) * memo.count(new_memo[c-1])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

K = 2
ans_list = []
ans = 0
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans_list = [a, b, c]
            gcd_ans = ans_list[0]
            for item in ans_list:
                gcd_ans = math.gcd(gcd_ans, item)
            ans += gcd_ans
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(sys.stdin.readline())
S = list(sys.stdin.readline().rstrip())
R = [i for i, x in enumerate(S) if x == "R"]
G = [j for j, y in enumerate(S) if y == "G"]
B = [k for k, z in enumerate(S) if z == "B"]
B_C = len(B)
ans = 0
for r in R:
    for g in G:
        ans += B_C
        cM = 2 * max(r, g) - min(r, g)
        cm = 2 * min(r, g) - max(r, g)
        if cM in B:
            ans -= 1
        if cm in B:
            ans -= 1
        if (r + g) % 2 == 0:
            cT = int((r + g) / 2)
            if cT in B:
                ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())

def gcd(a, b):
    r = a % b
    return gcd(a, r) if r else a
  
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(i, gcd(j, k))

print(sum_)

Submission status: Wrong Answer

Solution code:
import math
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
a=int(input())
ans=0
for i in range(1,a+1):
  for j in range(1,a+1):
    n=math.gcd(i+1,j+1)
    for k in range(1,a+1):
      ans+=math.gcd(n,k+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import functools
import math

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


def gcd(nums):
    return functools.reduce(math.gcd,nums)


#N = list(map(int, input().split()))

K = int(input())
SUM = 0
for a in range(K):
    a += 1
    for b in range(K):
        b += 1
        for c in range(K):
            c += 1
            NUMS = [a,b,c]
            SUM += euclid(euclid(a,b),c)
            print("{}, {}".format(NUMS,SUM))
print("{}".format(SUM))

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

a=1;b=1;c=1;d=0
n=int(input());
for i1 in range(n):
	for i2 in range(n):
		for i3 in range(n):
			d+=reduce(math.gcd,(a,b,c))
			c+=1
		b+=1
	a+=1
print(d)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

a=1;b=1;c=1;d=0
n=int(input())
for i1 in range(n):
	for i2 in range(n):
		for i3 in range(n):
			d+=reduce(math.gcd,(a,b,c))
			c+=1
		b+=1
	a+=1
print(d)

Submission status: Wrong Answer

Solution code:
from math import gcd

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
  if a < b:
    a_init = a
    b = a
    a = a_init
  while b != 0:
    r = a % b
    a = b
    b = r
  return a
	
K = int(input())
count = 0
temp = []
for a in range(1, K+1):
	for b in range(1, a):
		temp.append(gcd(a, b))
for c in range(1, K+1):
	for j in range(len(temp)):
		count += gcd(c, temp[j]) * 2
	for k in range(1, K+1):
		count += gcd(c, k)
print(count)

Submission status: Wrong Answer

Solution code:
from math import gcd

def threegcd(a, b, c):
    return min(gcd(a,b), gcd(b,c), gcd(c,a))

k = int(input())

ans = 0

for i in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            ans += threegcd(i, j, k)

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b,c):
  x=0
  for i in range(min([a,b,c])):
    if a%(i+1)==0 and b%(i+1)==0 and c%(i+1)==0:
      x=i
  return x

def sum(k):
  s=0
  for x in range(k+1):
    for y in range(k+1):
      for z in range(k+1):
        s+=gcd(x+1,y+1,z+1)
  return s
i=int(input())
o=sum(i)
print(o)

Submission status: Wrong Answer

Solution code:
K = int(input())
gcd_sum = 0
for a in range(1,K+1):
	a_init = a
	for b in range(1, K+1):
		b_init = b
		for c in range(1, K+1):
			a = a_init
			b = b_init
			m = min(a, b, c)
			gcd = 1
			for i in range(2, m+1):
				if a%i == 0 and b%i == 0 and c%i == 0:
					a /= i
					b /= i
					c /= i
					gcd *= i
			gcd_sum += gcd
print(gcd_sum)

Submission status: Wrong Answer

Solution code:
from math import *

K = int(input())

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

print(sum)

Submission status: Wrong Answer

Solution code:
from math import *

K = int(input())

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

print(sum)

Submission status: Wrong Answer

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


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


k = int(input())
sumV = 0
# start = datetime.now()
for a in range(1, k):
    for b in range(1, k + 1):
        for c in range(2, k + 1):
            sumV += gcd(a, b, c) * 3
sumV += 1
sumV += k

# end = datetime.now()
# print(end - start)
print(sumV)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# P3:
def get_gcd(numbers):
    """Helper function to get GCD of list of numbers."""
    import math
    from functools import reduce

    if 1 in numbers:
        return 1

    # gcd is associative
    return reduce(lambda x, y: math.gcd(x, y), numbers)


def sum_of_gcd_tuples():
    K = int(input())
    total = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            for c in range(1, K + 1):
                total += get_gcd([a, b, c])

    print(total)

Submission status: Wrong Answer

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

for i in range(1,n+1):
    for j in range(n):
        for k in range(n):
            gcdsum += gcd(i, gcd(j,k))

print(gcdsum)

Submission status: Wrong Answer

Solution code:
k = int(input())
ans = []
for a in range(1,k+1):
    for b in range (1,a+1):
        for c in range (1,b+1):
            for i in range(1,c+1)[::-1]:
                if a%i == 0 and b%i == 0 and c%i == 0:
                    ans.append(i)
                    break
print(sum(ans)*3 - 2*sum(range(1,k+1)))

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
ans=0
d={}
if n==1:
    print(1)
for a in range(1,n+1):
    for b in range(1,n+1):
        p=math.gcd(a,b)
        if d.get(p)!=None:
            d[p]+=1
        else:
            d[p]=1
for c in range(1,n+1):
    for e in range(1,n+1):
        p=math.gcd(c,e)
        ans+=d[e]*p
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

n = int(input())

answer = 0.0

for i in range(1,n+1):
  
  for j in range(1,n+1):
    
    for h in range(1,n+1):
      f = gcd(i,j,h)
      answer += f
      
print(answer)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import math
n = int(input())
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += math.gcd(x[0],x[1])*6
        else:
            tmp = math.gcd(x[0],x[1])
            ans += math.gcd(x[2],tmp)*6

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import fractions
n = int(input())
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += fractions.gcd(x[0],x[1])*6
        else:
            tmp = fractions.gcd(x[0],x[1])
            ans += fractions.gcd(x[2],tmp)*6

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

# reduce(function, iterable, initializer)
def gcd(*number):
    return reduce(math.gcd, number)

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

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

print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

# reduce(function, iterable, initializer)
def gcd(*number):
    return reduce(math.gcd, number)

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

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

print(sum)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

K = int(input())
sum = 0

@lru_cache()
def gcd(x,y):
  r = x % y
  while r> 0:
    x = y
    y = r
    r = x%y
  return y
  
for a in range(K):
  for b in range(K):
    for c in range(K):
      sum += gcd(gcd(a+1,b+1),c+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def gcd3(a, b, c):
    z = gcd2(a, b)
    return(gcd2(c, z))

k = int(input())
t = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            t += gcd3(a, b, c)
print(t)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
  
def gcd3(a,b,c):
  b=gcd(b,c)
  return gcd(a,b)
  
  
if __name__=="__main__":
  K = int(input())
  ans = 0
  for i in range(K):
    for j in range(K):
      for k in range(K):
        num = gcd3(i+1, j+1, k+1)
        print(i+1,j+1,k+1,num)
        ans += num
  print(ans)

Submission status: Wrong Answer

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

for i in range(1,k+1):
    a = i**3
    b = (i-1)**3
    c = (a-b)*(k-i+1)
    n += c

print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())

def ca(a,b):
    if a == 1:
        return 1
    while True:
        if a == 1:
            return 1
        if a == 0:
            return b
        t = a
        a = b %a
        b = t
    return b

def cal(a,b,c):
    mo = ca(a,b)
    ans = ca(mo,c)
    return ans


ans = 0
for a in range(1,K-1):
    ans += a
    ans += 6*cal(a,a,K)
    for b in range(a+1,K):
        ans += 6*cal(a,b,b)
        for c in range(b+1,K+1):
            ans += 6*cal(a,b,c)
    
ans += K + K-1 +6
if K == 2:
    print('9')
else:

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N=int(input())
count = 0

for i in range(1,N+1):
    i_ins=[]
    for x in range(1,i+1):
        if i//x != 0 and i%x == 0:
            i_ins.append(x)
    for j in range(1,N+1):
        i_j_ins=[]
        for y in i_ins:
            if j//y != 0 and j%y == 0:
                i_j_ins.append(y)
        if i_j_ins[-1]==1:
            print(i,j,i_j_ins[-1])
            count = count + i_j_ins[-1]*N
        else:
            for k in range(1,N+1):
                i_j_k_ins=[]
                for z in reversed(i_j_ins):
                    if k//z != 0 and k%z == 0:
                        i_j_k_ins.append(z)
                        break
                print(i,j,k,i_j_k_ins[-1])
                count = count + i_j_k_ins[-1]

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N=int(input())
count = 0
j_check = 0
k_check = 0

for i in range(1,N+1):
    i_ins=[]
    for x in range(1,i+1):
        if i//x != 0 and i%x == 0:
            i_ins.append(x)
    for j in range(i,N+1):
        i_j_ins=[]
        for y in i_ins:
            if j//y != 0 and j%y == 0:
                i_j_ins.append(y)
        for k in range(j,N+1):
            i_j_k_ins=[]
            for z in reversed(i_j_ins):
                if k//z != 0 and k%z == 0:
                    i_j_k_ins.append(z)
                    break
            print(i,j,k,i_j_k_ins[-1])
            if i==j and j==k and k==i:
                count = count + i_j_k_ins[-1]
            elif i==j or j==k or k==i:
                count = count + i_j_k_ins[-1]*3
print(count)

Submission status: Wrong Answer

Solution code:
K = int(input())

import math
import itertools
from functools import reduce

l = list(range(1, K+1))

h_list = list(itertools.combinations_with_replacement(l, 3))

a = 0

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

for val in h_list:
  a += gcd(val[0], val[1], val[2])
  
print(a)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

a=int(input())
b=[a]

for i in range(1,a):
    for j in range(i,a+1):
        for n in range(j,a+1):
            c=reduce(math.gcd,[i,j,n])
            if i==j and j==n:
                b.append(c)
            else:
                b.append(c*3)

print(sum(b))

Submission status: Wrong Answer

Solution code:
import math

memo = {}


def gcd(a, b, c):

    key = ''.join(map(str, sorted([a, b, c])))
    if key in memo:
        return memo[key]
    else:
        w = math.gcd(a, b)
        ans = math.gcd(w, c)
        memo[key] = ans
        return ans


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
k=int(input())
def solve(a,b,c):
	if a==0 or b==0 or c==0:
		return max(a,b,c)
	if a==b and b==c:
		return a
	if a<=b<=c:
		return solve(a,b%a,c%a)
	elif b<=a<=c:
		return solve(a%b,b,c%b)
	else:
		return solve(a%c,b%c,c)
arr=[i+1 for i in range(k)]

l = [p for p in itertools.product(arr, repeat=3)]
s=0
for i in l:
	a,b,c=i
	s+=solve(a,b,c)
print(s)

Submission status: Wrong Answer

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

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

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

print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

K = input('')
K=int(K)
la = lb = lc = list(range(1, K+1))
sum = 0

for a in range (len(la)):
  for b in range(len(lb)):
    for c in range(len(lc)):
      sum += gcd(la[a],lb[b],lc[c])

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

def sumgcd(K):
  for a in range (len(la)):
    for b in range(len(lb)):
      for c in range(len(lc)):
        sum += gcd(la[a],lb[b],lc[c])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(n, m):
	if m == 0:
		return n
	return gcd(m, n % m)


K = input()
s = 0

for i in range(int(K)):
	for j in range(int(K)):
		for k in range(int(K)):
			a = gcd(i + 1, j + 1)
			s += gcd(a, k + 1)

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

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

s=0

def check(a, b):
  judge=False
  while(judge==False):
    a,b=b,a%b
    if(b==0):
      judge = True
      return a
    elif(b==1):
      return 1
    
for i in range(1, n+1):
  for j in range(1, n+1):
    for k in range(1, n+1):
      s+=min([math.gcd(i,j), math.gcd(j,k), math.gcd(k,i)])


print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())

s=0
x=0

def check(a, b):
  judge=False
  tmp=0
  while(judge==False):
    a,b=b,a%b
    if(b==0):
      judge = True
      return a
    
for i in range(1, n+1):
  for j in range(1, n+1):
    for k in range(1, n+1):
      s+=min([check(i,j), check(j,k), check(k,i)])


print(s)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N=int(input())
count = 0
check = 0
for i in range(1,N+1):
    for j in range(i,N+1,i):
        for k in range(j,N+1,i):
            max_val = np.max([i,j,k])
            min_val = np.min([i,j,k])
            if i//min_val!=0 and i%min_val==0 and j//min_val!=0 and j%min_val==0 and k//min_val!=0 and k%min_val==0:
                for l in range(i,max_val+1,i):
                    #                    print(l,i,j,k)
                    if i//l!=0 and i%l==0 and j//l!=0 and j%l==0 and k//l!=0 and k%l==0:
                        if i==j and j==k and k==l:
                            count = count + l
                            break
                        else:
                            count = count + 3*l
                            check = 1
                            break

print(count)

Submission status: Wrong Answer

Solution code:
K = int(input())
print(int(K ** 3 + (1 / 2) *K ** 2 - (1 / 2) * K))

Submission status: Wrong Answer

Solution code:
K = int(input())
print(K ** 3 + (1 / 2) *K ** 2 - (1 / 2) * K)

Submission status: Wrong Answer

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


def gcds(a, b, c):
    d = gcd(a, b)
    e = gcd(d, c)
    return e


sum = 0
for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if i == j and j == k:
                sum = sum+gcds(i, j, k)
            elif i == j:
                sum = sum+2*gcds(i, j, k)
            else:
                sum = sum+6*gcds(i, j, k)

print(sum)

Submission status: Wrong Answer

Solution code:
import math

ans = 0
k = int(input())
for a in range(k):
    for b in range(k):
        tmp = math.gcd(a, b)
        for c in range(k):
            ans += math.gcd(tmp, c)

print(ans)

Submission status: Wrong Answer

Solution code:
#c
import math
k=int(input())
sum(math.gcd(math.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:
k = int(input())
list=[]
import math

for i in range(k+1):
    for j in range(k+1):
        for m in range(k+1):
            n = math.gcd(i,j)
            a = math.gcd(n,m)
            list.append(int(a))

ans = sum(list)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    k = ii()
    ans = 0
    for a in range(1, k+1):
        for b in range(1, k+1):
            for c in range(1, k+1):
                ans += math.gcd(math.gcd(a, b), c)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())
print(((2**K)-1)+K)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))





n  = in_int()



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


ans  = 0
for i in range(1, n+1):
    xx= n//i
    if xx >=1 :
        ans += i
    if xx>=2:
        ans += 3*xx*i
    if xx>=3:
        ans += 6 * xx * (xx - 1)  * i


print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
sum = 0

for i in range(N):
    for j in range(N):
        for k in range(N):
            g = math.gcd(i,j)
            sum += math.gcd(g,k)

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def calc_gcd(a,b):
  if a&b==0:
    return b
  else:
    return calc_gcd(b,a%b)

def gcd_sum():
  K = int(input())
  sum=0
  for i in range(1,K+1):
    for j in range(1,K+1):
      i_j=calc_gcd(i,j)
      for k in range(1,K+1):
        sum=sum+calc_gcd(i_j,k)
  return sum
print(gcd_sum())

Submission status: Wrong Answer

Solution code:
def calc_gcd(a,b):
  if a&b==0:
    return b
  else:
    return calc_gcd(b,a%b)

def gcd_sum():
  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=sum+calc_gcd(calc_gcd(i,j),k)
  return sum
print(gcd_sum())

Submission status: Wrong Answer

Solution code:
import io


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


def __main__():
    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(c, gcd(a, b))

    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())
f=0
g=0
h=0
import math
for a in range(1,k+1):
    for b in range(1,a+1):
        for c in range(1,b):
            d=math.gcd(a,b)
            e=math.gcd(d,c)
            f+=e
for a in range(1,k+1):
    for b in range(1,a):
        for c in range(1,b):
            d=math.gcd(a,b)
            e=math.gcd(d,c)
            g+=e
h=int((1+k)*k/2)
i=h+((f-g)*3)+g*6
print(i)

Submission status: Wrong Answer

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

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = gcd(a,b)
            g = gcd(g,c)
            print("{} {} {} g={}".format(a,b,c,g))
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            print("{} {} {} g={}".format(a,b,c,g))
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

Submission status: Wrong Answer

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

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

print(gcd)

Submission status: Wrong Answer

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

print(gcd)

Submission status: Wrong Answer

Solution code:
#ユークリッドの互除法

def euclid(m,n):
    # m > n となるように入れ替え
    if m < n:
        m, n = n, m
    while n != 0:
        m, n = n, m % n
    return m


num = int(input('')) #input()で入力を受け取ってint()で数字型に変換します。
ans_sum = 0

for a in range(1,num+1):
    for b in range(1,num+1):
        gcd_ab = euclid(a,num+1)
        for c in range(1,num+1):
            ans_sum = ans_sum + euclid(gcd_ab,c)

ans_sum = ans_sum

print(ans_sum)

Submission status: Wrong Answer

Solution code:
#ユークリッドの互除法

def euclid(m,n):
    # m > n となるように入れ替え
    if m < n:
        m, n = n, m
    while n != 0:
        m, n = n, m % n
    return m


num = int(input('')) #input()で入力を受け取ってint()で数字型に変換します。
ans_sum = 0

for a in range(1,num+1):
    for b in range(1,a):
        gcd_ab = euclid(a,num+1)
        for c in range(1,num+1):
            ans_sum = ans_sum + euclid(gcd_ab,c)

ans_sum = ans_sum

print(ans_sum)

Submission status: Wrong Answer

Solution code:
#ユークリッドの互除法

def euclid(m,n):
    # m > n となるように入れ替え
    if m < n:
        m, n = n, m
    while n != 0:
        m, n = n, m % n
    return m


num = int(input('')) #input()で入力を受け取ってint()で数字型に変換します。
ans_sum = 0

for a in range(1,num+1):
    for b in range(1,a):
        gcd_ab = euclid(a,num+1)
        for c in range(1,num+1):
            ans_sum = ans_sum + euclid(gcd_ab,c)

ans_sum = ans_sum * 2

print(ans_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans = 0

for i in range(1, N+1):
    for j in range(1, N+1):
        ans += gcd(i, j)

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math
K = [i for i in range(1, int(input()) + 1)]
numbers = itertools.combinations_with_replacement(K, 3)

sum_gcd = 0
for i in numbers:
    a = math.gcd(i[0], i[1])
    b = math.gcd(a, i[2])

    if i[0] != i[1] or i[1] != i[2] or i[0] != i[2]:
        sum_gcd += b * 3
    else:
        sum_gcd += b

print(sum_gcd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import time

import numpy as np 

# Input Stdin
## 1 <= K <= 200

K = int(input())

time0 = time.time()

sum_gcd = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            sum_gcd = sum_gcd + np.gcd.reduce(np.array([a, b, c]))

print(sum_gcd)

time1 = time.time()
print('{0:.3f}s'.format(time1 - time0))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
for i in range(n+1):
    if i % 3 != 0 and i % 5 != 0: ans += i
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):
    tmp = gdc(a+1, b+1)
    for c in range(K):
      total += gdc(tmp, c+1)
print(total)

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
d = 0
res = [ele for ele in product(range(1,N+1),repeat=3)]
a =(res)
for i in a:
    if i[0]==i[1]==i[2]:
        d = d+i[0]
    else:
        d = d+1
print(d)