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: Runtime Error

Solution code:
N,K = map(int, input().split())

g2 = [[0]*(K+1) for _ in range(K+1)]
def gcd(a, b):
    if g2[a][b] > 0:
        return g2[a][b]
    tmpa = a
    tmpb = b
    while b > 0:
        a,b = b, a%b
    g2[tmpa][tmpb] = a
    g2[tmpb][tmpa] = a
    return a

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

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

print(sm)

Submission status: Runtime Error

Solution code:
import copy
K=int(input)
primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
yakusuu_array=[]
for i in range(200):
  i+=1
  tmp=[]
  while i!=1:
    for prime in primes:
      if i % prime ==0:
        tmp.append(prime)
        i//=prime
  yakusuu_array.append(tmp)


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

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

Submission status: Runtime Error

Solution code:
K = int(input())

total = 0

mylist = list()
mylist1 = list()

for i in range(1, K + 1):
    for q in range(1, K + 1):
        for w in range(1, K + 1):
            z = str(i) + str(q) + str(w)
            mylist.append(z)

for i in mylist:
    a = int(i) // 10
    b = int(a) // 10
    c = int(c) // 10
    num = 0
    for e in range(1, 201):
        if int(a) % e == 0 and int(b) % e == 0 and int(c) % e == 0:
            if num <= e:
                num = e
    total = total + num

print(total)

Submission status: Runtime Error

Solution code:
 import math

K = int(input())
gcd_map = [[[0] * K for i in range(K)] for j in range(K)]

ans = 0

for a in range(1, K+1):
	for b in range(1, K+1):
		for c in range(1, K+1):
				if gcd_map[a-1][b-1][c-1] == 0:
					gcd = math.gcd(math.gcd(a,b), c)
					gcd_map[a-1][b-1][c-1] = gcd
					gcd_map[a-1][c-1][b-1] = gcd
					gcd_map[b-1][a-1][c-1] = gcd
					gcd_map[b-1][c-1][a-1] = gcd
					gcd_map[c-1][a-1][b-1] = gcd
					gcd_map[c-1][b-1][a-1] = gcd
					ans += gcd
				else:
					ans += gcd_map[a-1][b-1][c-1]

print(ans)

Submission status: Runtime Error

Solution code:
import math
import itertools
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
list_gcd = list(itertools.product(range(1, K+1), repeat=3))
result = {}
for i in range(K * K * K):
    result += math.gcd(*list_gcd[i])
print(result)

Submission status: Runtime Error

Solution code:
k = int(input())
import fractions as f
a = [1]*3
total = 0
for i in range(1,k+1):
    total += f.gcd(a[0],a[1],a[i])
for i in range(1,k+1):
    total += f.gcd(a[0],a[i],a[2])
    if i == k:
        for j in range(1,k+1):
            total += f.gcd(a[0],a[i],a[j])
for i in range(1,k):
    total += f.gcd(a[i],a[1],a[2])
    if i == k:
        for j in range(1,k+1):
            total += f.gcd(a[i],a[1],a[j])
            if j == k:
                for l in range(1,k):
                    total += f.gcd(a[i],a[l],a[j])


print(total)

Submission status: Runtime Error

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(k, N + 1)
            cnt += gcd(i, j, k)
print(cnt)

Submission status: Runtime Error

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

def gdc(x,y):
  if x%y==0:
    return y
  return gdc(y, x%y)

for a in range(K):
  for b in range(a,K):
    for c in range(b,K):
      if a==b and b==c:
        total += gdc(c+1, gdc(b+1, a+1))
      elif a==b or b==c or a==c:
        total += 3*gdc(c+1, gdc(b+1, a+1))
      eles:
        total += 6*gdc(c+1, gdc(b+1, a+1))
print(total)

Submission status: Runtime Error

Solution code:
import fractions

k=int(input())

sum= 0

one = 0
for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            f1 = fractions.gcd(a,b)
            f2 = fractions.gcd(f1,c)
            one = one+f2 
one = one *6

two = 0
for a in range(1,k+1):
    for b in range(b+1,k+1):
        f1 = fractions.gcd(a,b)
        two = two + f1
two = two *3

three=0
for a in range(1,k+1):
    three = three +a
sum = one + two + three
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from math import gcd
K = int(input())
A=[]
B=[]
sum=0
for a in range(1,K+1):
    for b in range(1,K+1):
        A.append(gcd(a,b))
for c in range(1,K+1):
    for d in range(1,K+1):
        B.append(gcd(A[c],d))
        sum+=B[c]
print(sum)

Submission status: Runtime Error

Solution code:
K = int(input())

def gcd(num1, num2):
  if num2 > num1:
    num1 , num2 = [num2, num1]
  else:
  	if num1 % num2 == 0:
      return num2
    else:
      r = num1 % num2
      return gcd(num2, r)

all_sum = 0

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

print(all_sum)

Submission status: Runtime Error

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: Runtime Error

Solution code:
import itertools
import fractions
from functools import reduce
k = int(input())
num = []
for i in range(1, k+1):
    num.append(i)
    num.append(i)
    num.append(i)
permutation_num = set(itertools.permutations(num, 3))
x = []
for j in s:
    y = reduce(fractions.gcd, j)
    x.append(y)

print(sum(x))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
for i in range(1,K+1):
    a = i
    for j in range(1,K+1):
        b = j
        for k in range(1,K+1):
            c = k
            g = gcd(a,b,c)
            res = res + g
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np

#N = int(input())
N=10
#print(np.linspace(1, N, N))
c_1 = np.linspace(1, N, N)
c_temp = c_1.tolist()

A_temp = []
B_temp = []
C_temp = []


for i in range(N+1):
    a_temp = np.full(N*N, i)
    A_temp.extend(a_temp)
    
    for i in range(N+1):
        b_temp = np.full(N, i)
        B_temp.extend(b_temp)

        for i in range(N+1):
            C_temp.extend(c_1)
            C_temp.extend(c_temp)

a = np.array(A_temp)
b = np.array(B_temp)
c = np.array(C_temp)

print(np.gcd.reduce([a, b, c]))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from math import gcd
K = int(input())
A=[]
B=[]
sum=0
for a in range(1,K+1):
    for b in range(1,K+1):
        A.append(gcd(a,b))
for c in range(1,K+1):
    for d in range(1,K+1):
        B.append(gcd(A[c],d)
        sum+=B[c]
print(sum)

Submission status: Runtime Error

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])*(n+1)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

Submission status: Runtime Error

Solution code:
import math
import sympy
a=int(input())
sum=a*a
for i in range(2,a+1):
  for j in range(2,a+1):
    for k in range(2,a+1):
      if i=j=k:
        sum+=i
      else:
        if sympy.isprime(i)=="True" or sympy.isprime(j)=="True" or sympy.isprime(k)=="True":
          sum+=1
        else:
          an=math.gcd(i,j)
          bn=math.gcd(j,k)
          cn=math.gcd(an,bn)
          sum+=cn
print(sum,end="")

Submission status: Runtime Error

Solution code:
mport math
from functools import reduce

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


N=int(input())
S=0
T=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            S+=gcd(i,j,k)
for i in range(1,N+1):
    for j in range(i+1,N+1):
            T+=gcd(i,j,j)
            T+=gcd(i,j,j)
print(6*S+3*T+N*(N+1)//2)

Submission status: Runtime Error

Solution code:
import fractions
f=fractions.gcd(a,b)
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 += fractions.gcd(a, fractions.gcd(b, c))
print(ans)

Submission status: Runtime Error

Solution code:
def euc(i, j):
    if i > j:
        i, j = j, i
    while j%i != 0:
        k = abs(j - i)
        j = i%k
        i = k
        if i > j:
            i, j = j, i
    return i


N = int(input())
sum = 0
for i in range(1, N + 1):
    for j in range(1, N + 1): 
        ij = euc(i, j)
        for k in range(1, N + 1):
            sum += euc(ij, k)
print(sum)

#print(euc(9, 18))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    for i in range(200):
      a, b = b, a%b
      return a if b == 0
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

Submission status: Runtime Error

Solution code:
from fractions import gcd
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
        a=(i,j,l)
        if len(a)==1:
            ans=ans+i
        elif len(a)==2:
            ans=ans+fractions.gcd(a[0],a[1])
        else:
            ans=ans+fractions.gcd(a[0],fractions.gcd(a[1],a[2]))
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product

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

def gcb_3(a, b, c):
    return gcb(gcb(a, b), gcb(b, c))

k = int(input())
res = 0
l_k = range(1, k+1)
for part in itertools.product(l_k, l_k, l_k):
    res += gcb_3(part[0], part[1], part[2])
print(res)

Submission status: Runtime Error

Solution code:
import functools
import itertools
import math


@functools.lru_cache(maxsize=None)
def gcd(a, b):
    return math.gcd(a, b)


@functools.lru_cache(maxsize=None)
def gcd3(a, b, c):
    return gcd(gcd(a, b), c)


# 文字列1行
K = int(input().strip())
Kr = [range(1, K+1) for i in range(3)]

items = itertools.product(*Kr)

sum_ = 0
for p in items:
    p = sorted(p)
    mods = sum([a % 2, b % 2, c % 2])
    if 0 < mods < 3:
        sum_ += 1
    else:
        sum_ += gcd3(*p)
print(sum_)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from itertools import combinations

n = int(input())
cnt=0
for i in range(1,n+1):
    for j in range(1,n+1):
        if(i==j):
            cnt += i
        else:
            cnt += gcd(i,i,j)*3

if(n>=3):
    my_list = list(range(1,n+1))
    x = combinations(my_list, 3)

    list_x = list(x)
    for i in list_x:
        cnt+= gcd(i[0],i[1],i[2])

print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
s = 0
for i in range(0,N):
  if (i+1) % 3 1= 0 or (i+1) % 5 != 0:
    s = s + (i+1)
print(s)

Submission status: Runtime Error

Solution code:
import fractions

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

def gcd_list(a,b,c):
  return gcd(gcd(a,b),gcd(b,c))


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

print(count)

Submission status: Runtime Error

Solution code:
k=int(input())
    ans=0
    for x in range(1,k+1):
        for y in range(1,k+1):
            for z in range(1,k+1):
               if math.gcd(x,y)==1:
                   ans+=1
               
               elif math.gcd(math.gcd(x,y),z)==1: 
                   ans+=1
               else: 
                       ans+=math.gcd(math.gcd(x,y),z)
    print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce

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

k = int(input())

lists = []
for i in itertools.product(range(k), repeat=3):
    a = int(i[0]) + 1
    b = int(i[1]) + 1
    c = int(i[2]) + 1
    lista = (a, b, c)
    lists.append(lista)
        
ans = 0
for i in lists:
    ans += gcd(*(i))

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from itertools import combinations

n = int(input())
cnt=0
for i in range(1,n+1):
    for j in range(1,n+1):
        if(i==j):
            cnt += i
        else:
            cnt += gcd(i,i,j)*3

print(cnt)
if(n>=3):
    my_list = list(range(1,n+1))
    x = combinations(my_list, 3)


    list_x = list(x)
    for i in list_x:
        cnt+= gcd(i[0],i[1],i[2])

print(cnt)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

N = int(input())
sum = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(1,N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            sum += gcd(i,j,k)
            b.sort()
            a.append(b)
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
n_lst = []
for i in range(n):
    n_lst.append(i+1)
    
##共通
kosu = n // 15
 
##3の倍数
a3 = n // 3
lst3 = []
for i in range(a3):
    n3 = 3 * (i+1)
    lst3.append(n3)
 
##5の倍数
a5 = n // 5
lst5 = []
for i in range(a5):
    n5 = 5 * (i+1)
    lst5.append(n5)
 
kosu2 = a5 - kosu
    
###リストから取り除く.strip
for i in range(a3):
    n_lst.remove(lst3[i])
for i in range(kosu2):
    n_lst.remove(lst5[i])
    
goke = sum(n_lst)
print(goke)

Submission status: Runtime Error

Solution code:
k = int(input())

def extract_gcd(limit):
    ran = range(1, limit + 1)
    for i in ran:
        for j in ran:
            for k in ran:
                yield math.gcd(math.gcd(i, j), k)
total = 0
for n in extract_gcd(k):
    total += n
    
print(total)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <iomanip>
 
using namespace std;

int gcd(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

int tgcd(int a, int b, int c){
  int d = gcd(a, b);
  return gcd(c, d);
}

int main(){
  int K, tri, dub, mon;
  cin >> K;
  tri = K*(K+1) / 2;
  dub = 0;
  for (int i=1;i<K+1;i++){
    for (int j=1;j<K+1;j++){
      if (i < j){
        dub = dub + gcd(i, j);
      }
    }
  }
  mon = 0;
  for (int i=1;i<K+1;i++){
    for (int j=1;j<K+1;j++){
      for (int l=1;l<K+1;l++){
        if (i < j and j < l){
          mon = mon + tgcd(i, j, l);
        }
      }
    }
  }
  cout << tri+6*(mon+dub);
  return 0;  
}

Submission status: Runtime Error

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


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


K = int(input())

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

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

a=np.sum(temp_1)*6

temp_2 = np.array([])

for j in itertools.combinations(l, 2):
    temp_2=np.append(temp_2,gcd_list(list(j[0],j[0],j[1])))
    temp_2=np.append(temp_2,gcd_list(list(j[0],j[1],j[1])))
    
b=np.sum(temp_2)*3

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

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

Submission status: Runtime Error

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])
            elif lis in sumlis.values(): 
                ans+=sumlis[lis]
            else:
                x=gcdlist(lis)
                sumlis[x]=sumlis
                ans+=x
                
print(ans)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
import itertools

for l, m, n in itertools.product(range(k), range(k), range(k))

k = int(input())
tot = 0

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

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

Submission status: Runtime Error

Solution code:
a=int(input())
sum=0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      an=math.gcd(i,j)
      bn=math.gcd(j,k)
      cn=math.gcd(an,bn)
      sum+=cn
print(sum,end="")

Submission status: Runtime Error

Solution code:
K = inpit()
k = int(K)
a =0
for i in range (k+1):
    l = k//i
    a+= i*(l**3)
print(a)

Submission status: Runtime Error

Solution code:
K=int(input())
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):            
            m=min(a,b,c)
            for i in range(1,m+1):
                if a%i==0 and b%i==0 and c%i==0:
                    gcd=i
            sum+=gcd

print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
mport math
from functools import reduce

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

K=int(input())

i=1
j=1
k=1
r=0
list=[2,3,5,7,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]

while(i<K+1):
  j=1
  f=0
  if(i in list == True):
    f=1
  while(j<K+1):
    k=1
    g=0
    if(j in list == True):
      g=1
    while(k<K+1):
      h=0
      if(k in list == True):
        h=1
      if(i==1 or j==1 or k==1):
        r+=1
      elif(f==1 and g==1 and h==1):
        if(i==j and j==k):
          r+=i
        else:
          r+=1
      else:
        r+=gcd(i, j, k)
      k+=1
    j+=1
  i+=1

print(r)

Submission status: Runtime Error

Solution code:
from fractions import math

k = int(input())

g =[gcd(math.gcd(i+1, j+1), l+1) for i in range(k) for j in range(k) for l in range(k)]
print(sum(g))

Submission status: Runtime Error

Solution code:
K = int(input())
Nl = [int(x) for x in range(1,K+1)]
res = 0
for i in Nl:
    a = i
    for j in Nl:
        b = j
        for k in Nl:
            c = k
            g = gcd(a,b,c)
            res = res + g
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
k=int(input())
k+=1
a=[np.gcd(np.gcd(i,j),u)for i in range(1,k)for j in range(1,k)for u in range(1,k)]
print(np.npsum(a))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

k = int(input())
li = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      li.append(func(a,b,c))

print(sum(li))

Submission status: Runtime Error

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

import math
from functools import reduce
import itertools

K = intinp()

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

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

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
result = [0]*n**3
for a in range(n):
    for b in range(n):
        for c in range(n):
            if a > b:
                result[n*n*a +n*b + c]= result[n*n*b +n*a + c]
            elif b > c:
                result[n*n*a +n*b + c]= result[n*n*a +n*c + b]
            else:
                result[n*n*a +n*b + c] = gcd(a+1, gcd(b+1,c+1))
print(sum(result))

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    s = input()
    res = 0
    r = []
    g = []
    b = []
    for i, c in enumerate(s):
        if c == 'R':
            r.append(i)
        elif c == 'G':
            g.append(i)
        else:
            b.append(i)
    
    cnt = 0
    for i in r:
        for j in g:
            diff = abs(j-i)
            for k in b:
                if abs(i-k) != diff and abs(j-k) != diff and abs(j-k) != abs(i-k):
                    cnt += 1
    print(cnt)
                    


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
n = int(input())
print(sum([gcd(gcd(a,b),c) for a in range(1,n+1) for b in range(1,n+1) for c in range(1,n+1)]))

Submission status: Runtime Error

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

def main():
    def gcd(numbers): return reduce(math.gcd, numbers)
    K = int(input())
    ans = 0
    valiation = list(itertools.product(range(1, K+1), repeat=3))
    for v in valiation:
        ans += gcd(v)
    print(ans)
        
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
n = int(input())
print(sum([gcd(gcd(a,b),c) for a in range(1,n+1) for b in range(1,n+1) for c in range(1,n+1)]))

Submission status: Runtime Error

Solution code:
s

Submission status: Runtime Error

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

for a in range(1, k + 1):
    for b in range(1, k + 1):
        if gcd(a, b) == 1:
            total += 1 * k
            continue
        else:
            for c in range(1, k + 1):
                total += gcd(a, b, c)
print(total)

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    if x < y: x, y = y, x
    while y != 0:
        x, y = y, x % y
    return x

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):
            if i == j == k:
                ans += i
            elif i == k or j == k:
                continue
            elif i == j and j != k:
                ans += gcd(k, gcd(i, j)) * 3
            elif i < j < k:
                ans += gcd(k, gcd(i, j)) * 6
rint(ans)

Submission status: Runtime Error

Solution code:
k=int(input())
import math
if k==1:
    print(1)
else:
    s1=k*(k+1)//2
    s2=k-1
    for i in range(2,k):
        for j in range(i+1,k+1):
                s2+=math.gcd(i,j)
    s2=s2*6
    s3=0
    if k>2:
        for a in range(1,k-1):
            for b in range(a+1,k):
                for c in range(b+1,k+1):
                    s3+=math.gcd(math.gcd(a,b),c)
        s3=s3*6
print(s1+s2+s3)

Submission status: Runtime Error

Solution code:
import math

n = int(input())

print(sum([gcd(gcd(a,b),c) for a in range(1,n+1) for b in range(1,n+1) for c in range(1,n+1)]))

Submission status: Runtime Error

Solution code:
import math 
from itertools import product
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd,numbers)
K=int(input())
A=[]
as=range(1,K+1)
bs=range(1,K+1)
cs=range(1,K+1)
for a,b,c in product(as,bs,cs):
  s=gcd(a,b,c)
  A.append(s)
print(sum(A))
  
    
      A.append(s)
print(sum(A))

Submission status: Runtime Error

Solution code:
def gcd(m,n):
  x = max(m,n)
  y = min(m,)
  if x % y == 0:
    return y
  else:
    while x % y != 0:
      z = x % y
      x = y
      y = z
    else:
      return z
K = int(input())
x = 0
y = 0
z = 0

for i in range(1, K+1):
  for k in range(1, K+1):
    x = gcd(i,k)
    for j in range(1, K+1):
      y = gcd(x, j)
      z += y
print(z)

Submission status: Runtime Error

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

def main():
    def gcd(numbers): return reduce(math.gcd, numbers)
    K = int(input())
    ans = 0
    valiation = list(itertools.product(range(1, K+1), repeat=3))
    for v in valiation:
        ans += gcd(v)
#     for i in range(1, K+1):
#         for j in range(1, K+1):
#             for k in range(1, K+1):
#                 ans += gcd(i, j, k)
    print(ans)
        
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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

Submission status: Runtime Error

Solution code:
import math
import itertools
from numba import njit
 
@njit
def culc_gcd_of_3(l_p):
    answer = 0
    for x in l_p:
        temp = math.gcd(x[0], x[1])
        
        if temp == 1:
            answer += 1
        else:
            answer += math.gcd(x[2], temp)
    
    return answer
 
 
K = int(input())
l_p = list(itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)))
 
print(culc_gcd_of_3(l_p))

Submission status: Runtime Error

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

x = int(input())
print(sum([reduce(math.gcd, *i) for i in product(range(1, x+1), repeat=3)]))

Submission status: Runtime Error

Solution code:
import itertools
import collections
n = int(input())
ree = list(itertools.combinations_with_replacement(range(1, n+1), 3))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
re = []
for i in range(len(ree)):
  k = len(collections.Counter(ree[i]))
  if k == 3:
    re.append(gcd_list(list(ree[i])) * 6)
  elif k == 2:
    re.append(gcd_list(list(ree[i])) * 3)
  else:
    re.append(gcd_list(list(ree[i])))
print(sum(re))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from  itertools import combinations
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
li = list(combinations(use_li*3,3))
sum_li = []
for i in get_unique_list(li):
  sum_li.append(reduce(gcd,i))
sum(sum_li)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from itertools import combinations
 
x1 = int(input())
x2 = input()
RGB = {"R", "G", "B"}

peint(sum([1 for i, rgb in zip(combinations(range(x1), 3), combinations(x2, 3)) if set(rgb) == RGB and (i[1] - i[0]) != (i[2] - i[1])]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import itertools
from functools import reduce


a = int(input())
b = list(itertools.product(range(1,a+1),repeat=3))
c = 0


for i in b:
    n = reduce(math.gcd,i[0], i[1], i[2])
    c += n

print(c)

Submission status: Runtime Error

Solution code:
import functools
import itertools
import numpy

@functools.lru_cache(maxsize=None)
def gcd(p):
    return numpy.gcd.reduce(p)


# 文字列1行
K = int(input().strip())
Kr = range(1, K+1)

sum_ = 0
for p in itertools.product(Kr, Kr, Kr):
    sum_ += gcd(sorted(p))
print(sum_)

Submission status: Runtime Error

Solution code:
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
    r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(z,i3)
      s+=z2
print (s)

Submission status: Runtime Error

Solution code:
k = (int,input())
X =0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      m = max(a,b,c)
      x = 0
      for i in range(1,m+1):
        if a%m==0 and b%m==0 and c%m==0:
          x =i
      X += x

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

K = int(input())

sum1 = 0
sum2 = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            if i =< j =< k:
                sum1 += gcd(i, j, k)
            if i == j == k:
                sum2 += gcd(i, j, k)

print(sum1 * 3 - sum2 * 2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
n = int(input())

print(sum([gcd(a,b,c) for a in range(1,n+1) for b in range(1,n+1) for c in range(1,n+1)]))
print(sum(d))

Submission status: Runtime Error

Solution code:
def main(): # C163
    N = int(input())
    sum = 0
    for i in range(1, N+1):
        for j in range(1, N+1):
            for h in range(1, N+1):
                sum += gcd(i,j,h)
    print(sum)


main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from numba import jit

@jit
def gcd(*nums):
  return reduce(math.gcd, nums)


input_num = int(input()) + 1
result = 0
for a in range(1, input_num):
  for b in range(1, input_num):
    for c in range(1, input_num):
        result += gcd(a, b, c)
print(result)