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 itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    k = int(input())
    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            for l in range(k+1):
                ans += gcd(gcd(i,j),l)

    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

for a in range(1, K + 1):
    for b in range(a, K + 1):
        d = math.gcd(a, b)
        for c in range(b, K + 1):
            d = math.gcd(d, c)
            if a == b == c:
                m = 1
            elif a == b or b == c or c == a:
                m = 3
            else:
                m = 6
            ans += m * d

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input())
# a,bの最大公約数


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


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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
# N, K = map(int, input().split(' '))
N = int(input())
wa = 0
d = defaultdict(set)
d[1].add(1)

for i in range(2, 201):
    for j in range(i-1, 0, -1):
        if i % j == 0:
            d[i].add(j)

for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            #wa += 1
            wa += max(d[i] & d[j] & d[k])
print(wa)
# wa = 0
# for i in range(1, N+1):
#     if i % 3 == 0 or i % 5 == 0:
#         continue
#     wa += i
# print(wa)

Submission status: Wrong Answer

Solution code:
from math import *

K = int(input())

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math

K=int(input())
r=0

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

Submission status: Wrong Answer

Solution code:
K = int(input())

total = 0
for i in range(1, K + 1):
    for q in range(1, K + 1):
        num = 0
        for w in range(1, K + 1):
            for e in range(1, 201):
                if i % e == 0 and q % e == 0 and w % e == 0:
                    if num < e:
                        num = e
            total = total + num

print(total)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

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

print(sum)

Submission status: Wrong Answer

Solution code:
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

K = int(input())
sumXXX = 0
sumpattern = 0
sum = 0
b_list = []
for i in range(1, K+1):
    i_table = divisor(i)
    for j in range(1, K+1):
        for k in range(1, K+1):
            if i == j and j==k:
                sumXXX+= i
            # 羅列したことがあるlist
            elif sorted([i,j,k]) in b_list:
                continue
            else:
                b_list.append(sorted([i,j,k]))
                j_table = divisor(j)
                k_table = divisor(k)
                sumpattern += max(set(i_table) & set(j_table) & set(k_table))
sum = sumXXX + 3*sumpattern
print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())

sum=0
for i in range(1,n+1):
    if i%3==0:
        continue
    elif i % 5 == 0:
        continue
    else:
        sum += i

print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
K=int(input())
i=1
r=0
for i in range(K+1):
  j=1
  for j in range(K+1):
    k=1
    for k in range(K+1):
      if(i==1 or j==1 or k==1):
        r+=1
      elif(i==j and j==k):
        r+=i
      else:
        r+=math.gcd(i, math.gcd(j, k))
      k+=1
    j+=1
  i+=1
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
k=int(input())
count=0
for a in range(k):
  for b in range(k):
    for c in range(k):
      count+=gcd(gcd(a,b),c)
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
import math
K = int(input())
sum_gcd = 0
gcd = 0

primelist = []	
for i in range(1, K+1):	
    for j in range(2, int(math.sqrt(K)) + 1):	
        if i % j == 0:	
            primelist.append(i)

for a in range(K,0,-1):
    for b in range(K,0,-1):
        for c in range(K,0,-1):
            i = max(a,b,c)
            if a in primelist or b in primelist or c in primelist:
                if a == b and b ==c:
                    gcd = a
            else:    
                while i >= min(a,b,c):
                    if a % i == 0 and b % i == 0 and c % i == 0:
                        gcd = i  
                        break
                    i -= 1
                sum_gcd += gcd
print(sum_gcd)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

def main():
    K = int(input())
    l = []
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
                g = gcd(i, j, i*j)
                l.append(g)            
    print(sum(l))
main()

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce


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


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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import itertools
N = int(input())
l = []
 
for z in range (1, N + 1):
  for y in range(N + 1):
    l += [z]
p_set = set(itertools.combinations(l, 3))
s = 0
for i,j,k in p_set:
  t = gcd(i,j)
  t2 = gcd(t,k)
  if i == j and j == k:
    factor = 1
  elif i != j and i!= k and j != k:
    factor = 6
  else:
    factor = 3
  s += t2 * factor
print(s)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())

dp = [0 for _ in range(300)]
dp[1] = 1
for i in range(2,300):
	x = 2
	y = 0
	for j in range(1,i):
		y += math.gcd(j,i)
	for j in range(1,i):
		for l in range(1,i):
			y += math.gcd(j,l)
	dp[i] = x+y+dp[i-1]
print(dp[200])

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]
if K==1:
    print(3)
    exit()
num_list=[x for x in range(2,K+1,2)]
num2_list=[x for x in range(1,K+1,2)]
c_list = list(itertools.product(num_list,num_list,num_list))
kisuu=K**3-len(num_list)**3-len(num2_list)
c_list = list(set(map(tuple, (map(lambda x:sorted(x), 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*4
    elif j==k:
        ans += I * 4
    else:
        ans+=I*6
ans+=kisuu
ans+=sum(num2_list)
print(ans)

Submission status: Wrong Answer

Solution code:
def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y 
  
    return x 
      
      
l = [2, 4, 6] 
  
num1=l[0] 
num2=l[1] 
gcd=find_gcd(num1,num2) 
  
for i in range(2,len(l)): 
    gcd=find_gcd(gcd,l[i]) 
      
print(gcd)

Submission status: Wrong Answer

Solution code:
K = int(input())
 
def gcd(a, b):
  if b > a:
    a, b = b, a
  c = a % b
  if c == 0:
    return b
  return gcd(b, c)

ans = 0
ans += int((K+1)*K/2) #gcd(1, 1, 1)

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

'''
K = int(input())

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

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

print(ans)
'''

Submission status: Wrong Answer

Solution code:
N = int(input())

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

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

def main():
    K = int(input())
    l = []
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
                g = gcd(i, j, i*j)
                l.append(g)

Submission status: Wrong Answer

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

def gcd_xyz(x, y, z):
  xy = gcd(x, y)
  xyz = gcd(xy, z)
  return xyz

def past(p):
  if(p == 2):
    return 1
  else:
    return past(p-1)+(p-2)*4+6

K = int(input())

sum = K
K = K-1
i = 2
while(K>0):
  sum += ((i-2)*4+6 + past(i))*K
  K = K-1
  i+=1
print(sum)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())

dp = [0 for _ in range(300)]
dp[1] = 1
for i in range(2,300):
	x = 2
	y = 0
	for j in range(1,i):
		y += math.gcd(j,i)
	for j in range(1,i):
		for l in range(1,i):
			y += math.gcd(j,l)
	dp[i] = x+y+dp[i-1]
dp[200]

Submission status: Wrong Answer

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
ans = 0


def gcd(a,b):
    dv = 2
    c = a
    while a > 1:
        if b%c==0:
            return a
        if a%dv == 0:
            c = a//dv
        dv +=1
    return 1




dp = [[0]*(n+1) for i in range(n+1)]
for i in range(1,n):
    for j in range(i+1,n+1):
        dp[i][j] = gcd(i,j)

for i in range(1,n+1):
    dp[i][i] = i




if n == 1:
    print(1)

else:
    sl = []
    for i in range(2,n+1):
        for j in range(2,i):
            if i%j == 0:
                break
        else:
            sl.append(i)
        
    for i in range(1,n+1):
        for j in range(i,n+1):
            bv = dp[i][j]
            if i == j:
                seki = 3
            else:
                seki = 6

            for k in range(j,n+1):
                if i == j == k: continue
                
                elif i==k or j == k:
                    ans += dp[bv][k] * 3
                    # ans = gcd(bv,k) * 3
                else:
                    ans += dp[bv][k] * seki
                    # ans = gcd(bv,k) * seki
                # print(i,j,k,ans)
    for i in range(1,n+1):
        ans += i

    print(ans)

Submission status: Wrong Answer

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

for i in range(1, K + 1):
    ans += (K // i) ** 2 * i
    ans += K - (K // i) ** 2 // i

print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

K = int(input())
A = []
for i in range(2, K+1):
    if K%i == 0:
        A.append(i)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            if a in A and b in A and c in A:
                ans += reduce(gcd, [a, b, c])
            else:
                ans += 1
print(ans)

Submission status: Wrong Answer

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

List=range(1,K+1)          
D=0
for k, l, n in permutations(List, 3):
    D=D+math.gcd(k,math.gcd(l,n))*6

for i in range(1,K+1):
    if i < K:
        for i2 in range(i+1,K+1):
            D=D+math.gcd(i,i2)*6

for i3 in range(1,K+1):
    D=D+i3

    

print(D)

Submission status: Wrong Answer

Solution code:
import itertools
import math
from functools import reduce

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

ans = 0
k = int(input())
gcd_l = list(itertools.product(range(1,k+1), repeat=3))
print(gcd_l)
for i in gcd_l:
  	ans += gcd_list(i)
print(ans)

Submission status: Wrong Answer

Solution code:
#import fractions
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []
    #for i in range(k):
    #    for j in range(k):
    #        for l in range(k):
    #            lists.append((i+1,j+1,l+1))
    for i in range(k):
        lists.append(int(i+1))
        lists.append(int(i+1))
        lists.append(int(i+1))
    
    #for v in combinations_with_replacement(lists,3):
    #    print(v)
    lists = list(combinations_with_replacement(lists,3))
    #lists = sorted(set(lists))
    #print(lists)
    #lists2 = [i[0]*100+i[1]*10+i[2] for i in lists]
    #print(lists2)
        
    koubai = 0
    for i in lists:
        if len(set(i))==1:
            koubai = koubai + gcd(i[0],i[1],i[2])
            #print(koubai)
        elif len(set(i))==2:
            koubai = koubai + 3*gcd(i[0],i[1],i[2])
        else:
            koubai = koubai + 6*gcd(i[0],i[1],i[2])
            #print(koubai)
    print(koubai)
    



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import math
k=int(input())
ans=0
for x,y,z in itertools.combinations_with_replacement(range(2,k+1),3):
    ans+=math.gcd(math.gcd(x,y),z)
print(ans+3*((k-1)**2)+3*(k-1)+1)

Submission status: Wrong Answer

Solution code:
def gcd0(x, y):
    if y == 0:
        return x
    else:
        return gcd0(y, x % y)


def gcd(x,y,z):
    g = gcd0(x,y)
    return gcd0(g,z)

import itertools

k = int(input())
s = 0

if k == 2:
    print(9)
    exit()
if k == 1:
    print(1)
    exit()


seq = range(1,k+1)
t = list(itertools.combinations(seq,3))
for i in t:
    s += gcd(i[0],i[1],i[2])

s = s*8
l = 0
for i in range(1,k+1):
    l += i
s += l*4

print(s)

Submission status: Wrong Answer

Solution code:
import math
import itertools
from functools import reduce

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

K = int(input())
s = [gcd([i1, i2, i3]) for i1, i2, i3 in itertools.combinations_with_replacement(range(1,K+1), 3)]
print(sum(s))

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
n=int(input())
A=[]
B=[]
C=[]
X=[]
sum=0
sum=sum+n*n
for a in range(n):
    a=a+1
    for b in range(n):
        b=b+1
        for c in range(n):
            c=c+1
            if a==b or b==c or c==a:
                pass
            A.append(a)
            B.append(b)
            C.append(c)
for i in range(int(n*(n-1)*(n-2)/6)):
    x=gcd(A[i],B[i],C[i])
    sum=sum+x*6
for a in range(n):
    a=a+1
    for b in range(n):
        b=b+1
        if a==b:
            pass
        sum=sum+(math.gcd(a,b))*(n-1)*3
print(sum)

Submission status: Wrong Answer

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

def main():
    k = int(input())
    lists = []

    for i in range(k):
        lists.append(int(i+1))
        lists.append(int(i+1))
        lists.append(int(i+1))

    lists = list(combinations_with_replacement(lists,3))

        
    koubai = 0
    for i in lists:
        if len(set(i))==1:
            koubai = koubai + gcd(i[0],i[1],i[2])
            #print(koubai)
        elif len(set(i))==2:
            koubai = koubai + 3*gcd(i[0],i[1],i[2])
        else:
            koubai = koubai + 6*gcd(i[0],i[1],i[2])
            #print(koubai)
    print(koubai)
    



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import itertools
N = int(input())
l = []

for z in range (1, N + 1):
  for y in range(N + 1):
    l += [z]
p_set = set(itertools.combinations(l, 3))
print(len(p_set))
s = 0
for i,j,k in p_set:
  t = gcd(i,j)
  t2 = gcd(t,k)
  if i == j and j == k:
    factor = 1
  elif i != j and i!= k and j != k:
    factor = 6
  else:
    factor = 3
  s += t2 * factor
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

for i in range(K):
    for k in range(i,K):
        for j in range(i, K):
            if i == j == k:
                ans += gcd(i, k, j)
            else:
                if i == j or i == k or j ==k:
                    ans += gcd(i, k, j)*3
                else:
                    ans += gcd(i, k, j)
            j = j + 1
            k = k + 1
            i = i + 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
import math
K = int(input())
sum_gcd = 0
gcd = 0

primelist = []	
for i in range(1, K+1):	
    for j in range(2, int(math.sqrt(K)) + 1):	
        if i % j == 0:	
            primelist.append(i)

for a in range(K,0,-1):
    for b in range(K,0,-1):
        for c in range(K,0,-1):
            i = max(a,b,c)
            while i >= min(a,b,c):
                if a in primelist or b in primelist or c in primelist:
                    if a == b and b ==c:
                        gcd = a
                elif a % i == 0 and b % i == 0 and c % i == 0:
                   gcd = i  
                   break
                i -= 1
            sum_gcd += gcd
print(sum_gcd)

Submission status: Wrong Answer

Solution code:
n = int(input())

from math import gcd
def gcds(List):
    __ = 0
    for _ in List:
        __ = gcd(__, _)
    return __

x = []
y = []
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            temp = sorted([i,j,k])
            if temp not in x:
                x.append(temp)
                y.append(1)
            else:
                y[x.count(temp)] += 1
ans = 0
for p in range(len(y)):
    ans += (gcds(x[p]) * y[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())
A=[]
B=[]
C=[]
X=[]
sum=0
sum=sum+n*n
for a in range(n):
    a=a+1
    for b in range(n):
        b=b+1
        for c in range(n):
            c=c+1
            if a==b or b==c or c==a:
                pass
            A.append(a)
            B.append(b)
            C.append(c)
for i in range(int(n*(n-1)*(n-2)/6)):
    x=gcd(A[i],B[i],C[i])
    sum=sum+x
for a in range(n):
    a=a+1
    for b in range(n):
        b=b+1
        if a==b:
            pass
        sum=sum+(math.gcd(a,b))*(n-1)*3
print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools

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

k = int(input())
ans = 0

seq = [i for i in range(1, k+1)]
b = list(itertools.combinations_with_replacement(seq,3))

for a in b:
    if a[0] == a[1] == a[2]:
        ans += gcd(a[0], a[1], a[2])
    else:
        ans += gcd(a[0], a[1], a[2])*(k+1)
print(ans)

Submission status: Wrong Answer

Solution code:
final = dict()

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


A = [int(i) for i in input().split()]
dp = [[-1 for _ in range(len(A))] for _ in range(len(A))]

# Set GCD of single element as the elemnt itself
for i in range(len(A)):
    dp[i][i] = A[i]

# For every other subarrays of length l
# Calculate gcd using  length l - 1
for i in range(0, len(A)):
    for j in range(i + 1, len(A)):

        dp[i][j] = gcd(dp[i][j - 1], A[j])
        final[tuple(A[i: j + 1])] = dp[i][j]

print(final)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import itertools
N = int(input())
l = []
 
for z in range (1, N + 1):
  for y in range(N + 1):
    l += [z]
p_set = set(itertools.combinations(l, 3))
s = 0
for i,j,k in p_set:
  t = gcd(i,j)
  t2 = gcd(t,k)
  se = set([i,j,k])
  if len(se) == 1:
    factor = 1
  elif len(se) == 2:
    factor = 3
  else:
    factor = 6
  s += t2 * factor
print(s)

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import reduce

def gcd3(*numbers):
    return reduce(gcd, numbers)

k = int(input())

ans = k**2  - k + 1
for a in range(2, k):
    for b in range(2, k):
        for c in range(2, k):
            ans += gcd3(a, b, c)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import fractions
 
K = int(input())
dp = defaultdict(int)
 
def gcd(a,b):
  a,b = sorted([a,b])
 
  k = "".join([ str(x) for x in [a,b]])
  if not dp[k]:
    # dp[k] = F(a,b)
    dp[k] = fractions.gcd(a,b)
 
  return dp[k]
 
tmp = []
for a in range(1, K+1):
  for b in range(1, K+1):
    k = "".join([ str(x) for x in sorted([a,b])])
 
    if not dp[k]:
      dp[k] = gcd(a,b)
 
    tmp.append(dp[k])
 
res = 0
for t in tmp:
  for c in range(1, K+1):
    k = "".join([ str(x) for x in sorted([t,c])])
 
    if not dp[k]:
      dp[k] = gcd(t,c)
 
    res += dp[k]
 
print(res)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
n=int(input())
A=[]
B=[]
C=[]
X=[]
sum=0
sum=sum+n*n
for a in range(n):
    a=a+1
    for b in range(n):
        b=b+1
        for c in range(n):
            c=c+1
            if a==b or b==c or c==a:
                pass
            A.append(a)
            B.append(b)
            C.append(c)
    
for i in range(int(n*(n-1)*(n-2)/6)):
    x=gcd(A[i],B[i],C[i])
    sum=sum+x
    
for a in range(n):
    a=a+1
    for b in range(n):
        b=b+1
        if a==b:
            pass
        sum=(sum+math.gcd(a,b))*(n-1)
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())
ans=0
for i in range(k):
  for u in range(k):
    for y in range(k):
      ans+=gcd(i,u,y)
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    result=1
    N=min(a,b)
    for i in range(1,N+1):
        if a%i==0 and b%i==0 :
            result=i
    return result
K=int(input())
A=[]
sum=0
if K==1:
    print(1)
elif K==2:
    print(9)
else:
    for i in range(1,K):
        for j in range(i+1,K+1):
            tmp=[i,j,gcd(i,j)]
            A.append(tmp)
            sum+=tmp[2]*6
    for i in range(len(A)):
        for j in range(A[i][1]+1,K+1):
            sum+=gcd(A[i][2],j)*6
    for i in range(1,K+1):
        sum+=i
print(sum)

Submission status: Wrong Answer

Solution code:
k = int(input())

def gcd2(a, b): # a<=b
    if b%a==0:
        return a
    else:
        c = b%a
        if a < c:
            return gcd2(a, c)
        else:
            return gcd2(c, a)

def gcd3(a, b, c): #a<=b<=c
    if b%a==0 and c%a==0:
        return a
    else:
        if a == b:
            return gcd2(a, c)
        elif b == c:
            return gcd2(a, b)
        else:
            d = c%a
            if d == 0:
                d = a
            e = c%b
            if e == 0:
                e = b
            min = a
            if d < min:
                mid = min
                min = d
            else:
                mid = d
            if e < min:
                max = mid
                mid = min
                min = e
            elif e < mid:
                max = mid
                mid = e
            else:
                max = e
            if min == mid:
                return gcd2(min, max)
            elif mid == max:
                return gcd2(min, mid)
            else:
                return gcd3(min, mid, max)


sum = 0
for i in range(1, k+1):
    sum += i
for i in range(1, k):
    for j in range(i+1, k+1):
        sum += gcd2(i, j) * 6
for i in range(1, k-1):
    for j in range(i+1, k):
        for l in range(j+1, k+1):
            sum += gcd3(i, j, l) * 6
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import fractions
 
K = int(input())
dp = defaultdict(int)
 
def gcd(a,b):
  a,b = sorted([a,b])
 
  k = "".join([ str(x) for x in [a,b]])
  if not dp[k]:
    # dp[k] = F(a,b)
    dp[k] = fractions.gcd(a,b)
 
  return dp[k]
 
tmp = []
for a in range(1, K+1):
  for b in range(1, K+1):
    k = "".join([ str(x) for x in sorted([a,b])])
 
    if not dp[k]:
      dp[k] = gcd(a,b)

Submission status: Wrong Answer

Solution code:
k=int(input())
ans=0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
sumlis={}
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            lis=sorted([a,b,c])
            if lis in sumlis.values(): 
                ans+=sumlis[lis]
            elif 1 in lis:
                ans+=1
            elif sum(lis)==a*3:
                ans+=a
            else:
                x=gcdlist(lis)
                sumlis[x]=sumlis
                ans+=x
                
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]
if K==1:
    print(3)
    exit()
num_list=[x for x in range(2,K+1,2)]
num2_list=[x for x in range(1,K+1,2)]
c_list = list(itertools.product(num_list,num_list,num_list))
kisuu=K**3-len(num_list)**3-len(num2_list)
c_list = list(set(map(tuple, (map(lambda x:sorted(x), 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
ans+=kisuu
ans+=sum(num2_list)
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):
    a = gcd(gcd(a,b),c)
    return a

k = int(input())
ans = 0

num = list(itertools.combinations_with_replacement(range(1,k+1),3))
print(num)
for l in num:
    a,b,c = l
    if a==b==c:
        ans += a
    elif a!=b!=c:
        ans += gcd_3(a,b,c)*6
    else:
        ans += gcd_3(a,b,c)*3
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N=int(input())


#ことなる３つ
cnt1=0
for i in range(1, N+1-2):
    for j in range(i+1, N+1-1):
        for k in range(j+1, N+1):
            #print('i='+str(i)+' j='+str(j)+' k='+str(k))
            cnt1+=gcd(gcd(i,j),k)

#ことなる２つ
cnt2=0
for i in range(1, N+1-1):
    for j in range(i+1, N+1):
        cnt2+=gcd(i,j)*6

#全て同じ
cnt3=0
for i in range(1, N+1):
    cnt3+=i
    
print(cnt1+cnt2+cnt3)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import itertools
N = int(input())
l = []

for z in range (1, N + 1):
  for y in range(N + 1):
    l += [z]
p_set = set(itertools.combinations(l, 3))
s = 0
for i,j,k in p_set:
  t = gcd(i,j)
  t2 = gcd(t,k)
  se = set([i,j,k])
  if len(se) == 1:
    factor = 1
  elif len(se) == 2:
    factor = 3
  else:
    factor = 6
  s += t2 * factor
print(s)

Submission status: Wrong Answer

Solution code:
def find_gcd(x, y): 
    while(y): 
        x, y = y, x % y 
  
    return x 

l = [2, 4, 6, 8, 16] 
  
num1=l[0] 
num2=l[1] 
gcd=find_gcd(num1,num2) 
  
for i in range(2,len(l)): 
    gcd=find_gcd(gcd,l[i]) 
      
print(gcd)