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: Accepted

Solution code:
from math import gcd

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    from math import gcd
    K=I()
    ans=0
    
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                temp=gcd(i,j)
                temp=gcd(temp,k)
                ans+=temp
                
    print(ans)
                
    

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

L,R = map(int,input().split())
N_List = list(range(L,R+1))
N = len(N_List)
if N >= 2019:
    ans = 0
else:
    F = N_List[0] % 2019
    L = N_List[-1] % 2019
    if F < L:
        ans = 2019
        Amari_List = list(range(F,L+1))
        for v1,v2 in itertools.combinations(Amari_List, 2):
            if v1*v2 < ans:
                ans = v1*v2
    else:
        ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int M = 1e9+7;

int mul(int a, int b){
    return 1LL*a*b%M;
}

int add(int a, int b){
    return (a%M+b%M)%M;
}

int sub(int a, int b){
    return ((a%M - b%M)+M)%M;
}

int pow(int a, int b){
    int res = 1;
    while(b>0){
        if(b&1) res = mul(res,a);
        a = mul(a,a);
        b/=2;
    }
    return res%M;
}


//this is the solution for problem E. reused it.
//simple soln is bruteforce
int main(){
    int n,k;
    cin>>k;
    n = 3;
    int res = 0;
    int arr[k+1];
    for(int i = k; i >= 1; i--){
           int t = pow(k/i, n); 
           for(int j = i*2; j<=k; j+=i) t = sub(t,arr[j]);
           res = add(res,mul(t,i));
           arr[i] = t;
    }
    cout<<res;
}

Submission status: Runtime Error

Solution code:
k = int(input())
def gcd1 (a, b):
    while True:
        if (a < b):
            a, b = b, a
        c = a%b
        if (c == 0):
            return (b)
        else:
            a = b
            b = c

def gcd2 (a, b, c):
    tmp = gcd1(a, b)
    ans = gcd1(tmp, c)
    return (ans)

count = 0
for i in range(k):
    for j in range(i, k):
        for l in range(j, k):
            tmp = gcd(i + 1, j + 1, l + 1)
            if (i == j == l):
                count = count + tmp
            elif (i == j or j == l):
                count = count + tmp*3
            else:
                count = count + tmp*6
print(count)

Submission status: Runtime Error

Solution code:
k = int(input())
def gcd1 (a, b):
    while True:
        if (a < b):
            a, b = b, a
        c = a%b
        if (c == 0):
            return (b)
        else:
            a = b
            b = c

def gcd2 (a, b, c):
    tmp = gcd1(a, b)
    ans = gcd1(tmp, c)
    return (ans)

count = 0
for i in range(k):
    for j in range(i, k):
        for l in range(j, k):
            tmp = gcd(i + 1, j + 1, l + 1)
            if (i == J == l):
                count = count + tmp
            elif (i == j or j == l):
                count = count + tmp*3
            else:
                count = count + tmp*6
print(count)

Submission status: Runtime Error

Solution code:
k = int(input())
def gcd1 (a, b):
    while True:
        if (a < b):
            a, b = b, a
        c = a%b
        if (c == 0):
            return (b)
        else:
            a = b
            b = c

def gcd2 (a, b, c):
    tmp = gcd1(a, b)
    ans = gcd1(tmp, c)
    return (ans)

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

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):
        a = gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(a,l)

print(ans)

Submission status: Runtime Error

Solution code:
[N, K] = [int(i) for i in input().split()]
print(min(N%K, -N%K))

Submission status: Runtime Error

Solution code:
import math

K = int(input())
sum = 0

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def main():
    K = int(input())
    ans = 0
    #全てが同じ数字
    for i in range(1,K+1,1):
        for j in range(1,K+1,1):
            for k in range(1,K+1,1):
                ans += gcd(i,j,k)

    return ans

print(ans)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
ans = [gcd(i+1, gcd(j+1, k+1)) for i in range(n) for j in range(n) for k in range(n)]
print(sum(ans))

Submission status: Runtime Error

Solution code:
k=int(input())

ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        an=fractions.gcd(i,j)
        for s in range(1,k+1):
            anse=fractions.gcd(s,an)
            ans+=anse
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math

k = int(input())
ans = 0

for a in range(1,k+1):
    if i == 1:
        ans += k*k
        continue
    for b in range(1,k+1):
        n = math.gcd(a,b)
        if n == 1:
            ans += k
            continue
        for c in range(1,k+1):
            ans += math.gcd(n,c)
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

k = int(input())
ans = 0

for a in range(1,k+1):
    if i == 1:
        ans += k*k
        continue
    for b in range(1,k+1):
        n = gcd(a,b)
        if n == 1:
            ans += k
            continue
        for c in range(1,k+1):
            ans += gcd(n,c)
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

k = int(input())
ans = 0

n = list(product([i for i in range(1,k+1)],repeat=3))
for a,b,c in n:
    n = gcd(a,b)
    ans += gcd(n,c)
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

k = int(input())
ans = 0

n = list(product([i for i in range(1,k+1)],repeat=3))
for a,b,c in n:
    n = gcd(a,b)
    ans += gcd(n,c)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    s = input()

    rr = [i for i, c in enumerate(s) if c == 'R']
    g = [i for i, c in enumerate(s) if c == 'G']
    b = [i for i, c in enumerate(s) if c == 'B']

    r = len(rr) * len(g) * len(b)
    for rre in rr:
        for ge in g:
            for be in b:
                r -= rre * 2 == ge + be
                r -= ge * 2 == rre + be
                r -= be * 2 == ge + rre
    print(r)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
program hi;
var 
    a, b, c, k, i, ans: longint;
    r: array[1..200] of longint;

procedure aswap(var x: longint; var y: longint);
var tmp: longint;
begin
    if x > y then begin
        tmp := x;
        x := y;
        y := tmp;
    end;
end;

function gcd(x: longint; y: longint): longint;
var i: longint;
begin
    aswap(x, y);
    for i := 1 to y do 
        if (x mod i = 0) and (y mod i = 0) then
            gcd := i;
end;

begin
    readln(k);
    for i := 1 to k do 
        r[i] := i;
    ans := 0;
    for c := 1 to k do 
        for b := 1 to k do 
            for a := 1 to k do 
                ans := ans + gcd(gcd(r[a], r[b]), r[c]);
    writeln(ans);
end.

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from functools import reduce

k = int(input())

wa = 0

for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            li = [a,b,c]
            wa += reduce(math.gcd,li)*6

for a in range(1,k+1):
    for b in range(a+1,k+1):
        wa += math.gcd(a,b)*6

for a in range(1,k+1):
    wa += a
    
print(wa)

Submission status: Runtime Error

Solution code:
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):
            if a == 1 or b == 1 or c == 1:
                ans = ans + 1
            elif a == 2 or b == 2 or c == 2:
                ans = ans + 2
            elif a == 3 or b == 3 or c == 3:
                ans = ans + 3
            else:
                for d in range(k+1,4,-1):
                    if a % d == 0 and b % d == 0 and c % d == 0:
                        d  = e
                        ans = ans + e
                        break
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

gcache = { }
s = 0

for a in range(1, k+1):
  for b in range(1, k+1):
    tup = (min(a, b), max(a, b))
    if tup not in gcache:
      gc = math.gcd(tup[0], tup[1])
      gcache[tup] = gc
    gc = gcache[tup]
    for c in range(1, k+1):
      tup = (min(c, gc), max(c, gc))
      if tup not in gcache:
        gc = math.gcd(tup[0], tup[1])
        gcache[tup] = gc
      gc = gcache[tup]
      s += gc

print(s)

Submission status: Runtime Error

Solution code:
from math import gcd

k = int(input())
gcd_sum = 0

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

print(gcd_sum)

Submission status: Runtime Error

Solution code:
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)
print(ans)

Submission status: Runtime Error

Solution code:
#162C
#Sum of gcd of Tuples (Easy)

import math

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

Submission status: Runtime Error

Solution code:
import math

    k = int(input())
    ans = 0

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

    print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
k=int(input())
cnt=0
for i in range(k):
  for p in range(k):
    for q in range(k):
      cnt+=gcd(i,p,q)
      
print(cnt)

Submission status: Runtime Error

Solution code:
K=int(input())

#関数定義(最大公約数)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

print(sum)

Submission status: Runtime Error

Solution code:
from itertools import combinations_with_replacement


def euclidean(num_list: list):
    a, b = sorted(num_list)
    while b % a != 0:
        redi = b % a
        b = a
        a = redi
    return a


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

result = 0
for comb in combinations_with_replacement(k_range, 3):
    min_abc = min(comb)
    gcd = euclidean(comb[0:2])
    gcd = euclidean([gcd, comb[2]])
    if comb[0]==comb[1] and comb[1]==comb[2]:
        coef = 1
    elif (comb[0]!=comb[1] and comb[1]!=comb[2]) and comb[2]!=comb[0]:
        coef = 6
    else:
        coef = 3
    result += i * coef
print(result)

Submission status: Runtime Error

Solution code:
import math

K = int(input())
sum_gcd = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        n = math.gcd(a, b)
        for c in range(1, K+1):
            sum_gcd += np.gcd(n, c)
print(sum_gcd)

Submission status: Runtime Error

Solution code:
from fractions import gcd

K = int(input())

ans = 0

for a in range(1,K+1) :
    for b in range(1,K+1) :
        for c in range(1,K+1) :
           X = fractions.gcd(a, b)
           Y = fractions.gcd(X, c)
           ans += Y

print(ans)

Submission status: Runtime Error

Solution code:
import math
import fractions import gcd
import numpy as np
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 a in range(1,K+1) :
    for b in range(1,K+1) :
        for c in range(1,K+1) :
           X = fractions.gcd(a, b)
           Y = fractions.gcd(X, c)
           ans += Y

print(ans)

Submission status: Runtime Error

Solution code:
import math
import fractions
import numpy as np
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 a in range(1,K+1) :
    for b in range(1,K+1) :
        for c in range(1,K+1) :
           X = fractions.gcd(a, b)
           Y = fractions.gcd(X, c)
           ans += Y

print(ans)

Submission status: Runtime Error

Solution code:
# C - Sum of gcd of Tuples (Easy)
from math import gcd
K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd(a,b,c)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
r=S.count('R')
g=S.count('G')
b=S.count('B')
c=0
for i in range(N):
  for j in range(i+1,N):
    h=2*j-i
    if h<=N-1:
      if S[i]!=S[j] and S[i]!=S[h] and S[j]!=S[h]:
        c+=1
ans=r*g*b-c
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import numpy as np
import itertools

n = int(input())
ans =0
for a,b,c in itertools.product(range(1,n+1),repeat=3):

    g = np.gcd(np.gcd(a,b),c)
    ans +=g
print(ans)

Submission status: Runtime Error

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

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 m in range(1,k+1):
      ans += math.gcd(i,j,m)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

Submission status: Runtime Error

Solution code:
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)

Submission status: Runtime Error

Solution code:
def main():
    k = int(input())
    k1 = k + 1

    sum = 0
    for i in range(1, k1):
        for j in range(1, k1):
            for m in range(1, k1):
                sum += math.gcd(math.gcd(i, j), m)
    print(sum)

main()

Submission status: Runtime Error

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

      
print(sum)

Submission status: Runtime Error

Solution code:
import math

K = int(input())

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        gcd2 = math.gcd(i.j)
        for c in range(1, K + 1):
            gcd = math.gcd(gcd2, c)
            Sum.append(gcd)

print(sum(Sum))

Submission status: Runtime Error

Solution code:
K = int(input())

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            gcd = gcd_list([a, b, c])
            Sum.append(gcd)

print(sum(Sum))

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
rom math import gcd

k = int(input())
total = 0
for a in range(1, k+1):
    t = gcd(a, b)
    for b in range(1, k+1):
        for c in range(1, k+1):
            # print(a, b, c, gcd(a, gcd(b, c)))
            total += gcd(t, c)
print(total) # sample_02 1982 ms

Submission status: Runtime Error

Solution code:
from fractions import gcd
from math import gcd

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

Submission status: Runtime Error

Solution code:
import numpy as np
K = int(input())

s = 0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      s += np.gcd(i,np.gcd(j,k))
      
print(s)

Submission status: Runtime Error

Solution code:
from math import math

K = int(input())
cnt = 0

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

Submission status: Runtime Error

Solution code:
K = int(input())

import math

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

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
def gcds(numbers):
  return reduce(gcd, numbers)
K = int(input())
ans = 0
for a in range(1, K + 1):
  for b in range(1, K + 1):
    for c in range(1, K + 1):
      ans += gcds(a, b, c)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
K = int(input())

sum = 0

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

Submission status: Runtime Error

Solution code:
import math

v = int(input())
sum = 0

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

print(sum)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if b > a:
        a, b = b, a
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
 K = int(input())
 ans = 0
 for a in range(K):
     for b in range(K):
         for c in range(K):
             tmp = gcd(a, b)
             ans += gcd(tmp, c)

Submission status: Runtime Error

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

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

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

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

print(total)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

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

total = 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 i == k:
        x = 1
      elif i != j and i != k and j != k:
        x = 6
      else:
        x = 3
        
      total += x * gcd_list([i, j, k])
print(total)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd
K = int(input())
plus = 0
for i in range(1, K+1):
	for a in range(1, K+1):
    	x = gcd(i, a)
    	for j in range(1, K+1):
            plus += gcd(x, j)
print(plus)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
worker_list = [0] * N

for i in range(0, N - 1):
    worker_list[A[i] - 1] += 1

for i in range(N):
    print(worker_list[i])

Submission status: Runtime Error

Solution code:
from math import gcd

def solve():
    K = int(input())
    ans = 0
    
    for i in range(1,K+1):
        num = [0, 0, 0]
        num[0] = i
        for k in range(1,K+1):
            num[1] = k
            for m in range(1,K+1):
                num[2] = m
                ans += reduce(gcd, num)
    return ans

print(solve())

Submission status: Runtime Error

Solution code:
%%time
import math
from functools import reduce

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

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

Submission status: Runtime Error

Solution code:
from sys import stdin


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


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin


def main():
    k = int(stdin.readline())

    g = [[[0 for _ in range(k)] for _ in range(k)] for _ in range(k)]

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            g[a - 1][b - 1][0] = fr.gcd(a, b)
            for c in range(b, k + 1):
                g[a - 1][b - 1][c - 1] = fr.gcd(g[a - 1][b - 1][0], c)

    ans = 0

    for a in range(k):
        for b in range(k):
            for c in range(k):
                abc = sorted([a, b, c])
                ans += g[abc[0]][abc[1]][abc[2]]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
form math import gcd
num = (int)(input())
total = 0
 
for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = gcd(i, j)
    for k in range(1, num + 1):
      total += gcd(sub, k)
print(total)

Submission status: Runtime Error

Solution code:
from math import gcd
num = (int)(input())
total = 0
 
for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = math.gcd(i, j)
    for k in range(1, num + 1):
      total += math.gcd(sub, k)
print(total)

Submission status: Runtime Error

Solution code:
# ABC 162

A = int(input())
# 最小公倍数
ans = 0
import math


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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
cnt = 0
for i in range(n):
	for j in range(n):
		for k in range(n):
			cnt += gcd(k,j,i)
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
cnt = 0
for i in range(n):
	for j in range(n):
    	for k in range(n):
        	cnt += gcd(k,j,i)
print(cnt)

Submission status: Runtime Error

Solution code:
k = int(input())
sum_ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd_ab = gcd(a, b)
        for c in range(1, k+1):
            gcd_abc = gcd(gcd_ab, c)
            sum_ans += gcd_abc
print(sum_ans)

Submission status: Runtime Error

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

K = readInt()
d = defaultdict(int)
ans=0
for a in range(1,K+1):
	for b in range(1,K+1):
		x = gcd(a,b)
		for c in range(1,K+1):
			ans+=gcd(x,c)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())

m = {'R': 0, 'G': 0, 'B': 0}

for i, c in enumerate(s):
  if c == 'R':
    m['R'] += 1
  elif c == 'G':
    m['G'] += 1
  else:
    m['B'] += 1

result = m['R'] * m['G'] * m['B']

for i in range(1, n - 1):
  for j in range(i + 1, n):
    k = 2 * j - i

    if k > n or not (s[i - 1] != s[j - 1] and s[j - 1] != s[k - 1] and s[k - 1] != s[i - 1]):
      continue
    result -= 1

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def sort_2(a,b):
    if b<a:
        c=a
        a=b
        b=c
    return [a,b]


def GCDbase(a,b):
    D=b//a
    if b==D*a:
        return a
    else:
        return GCD(b-a*D,a)
    
def GCD(a,b):
    ab=sort_2(a,b)
    return GCDbase(ab[0],ab[1])
    
    

K=int(input())
sum=0
for i in range(1,K+1):
    for j in range(1,K+1):
	t=GCD(i,j)
        for l in range(1,K+1):

            sum+=GCD(t,l)
print(sum)

Submission status: Runtime Error

Solution code:
import numpy

L = int(input())
print(numpy.sum([math.gcd(math.gcd(i + 1, j + 1), k + 1) for i in range(L) for j in range(L) for k in range(L)]))

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
import math


#整数の入力
N = int(input())
ans = 0

for i in range(N):
  for j in range(N):
    for k in range(N):
      ans = ans + math.gcd(i+1,j+1,k+1)
print(ans)
#print(math.gcd(a, b))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
  
ans=0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            
            ans+=gcd(a,b,c)  
print(ans)
n=int(input())

import math
from functools import reduce

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

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