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:

/*
    -> tested and removed line breaks from namespace amit
    -> pragma's now don't run on my machine making compilation fast
    ->
*/
#ifndef AMIT
#pragma GCC optimize("unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast")
#define dbg(...)
#define db(...)
#endif
#include "bits/stdc++.h"
using namespace std;using ll = long long;using ld = long double;

#define _(_1, _2, _3, _4, NAME, ...) NAME
#define f3(i, a, n, inc) for(int i = (a) - (inc < 0); (inc) > 0 ? i < (n) : i >= (n); i += (inc))
#define f2(i, a, n) f3(i, a, n, 1 - 2*(a > n))
#define f1(i, n) f2(i, 0, n)
#define f0(i) f2(i, 0, n)
#define fr(...) _(__VA_ARGS__, f3, f2, f1 , f0)(__VA_ARGS__)
#define trav(i,x) for(auto& i: x)
#define sz(x) ((int)x.size())
#define len(x) ((int)x.length())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define all(x) begin(x),end(x)
const ll MOD = 1e9+7;   //998244353
const ll INF = 2e18;const int inf = 2e9;

namespace amit{template<class T> void re(complex<T>& x); template<class T1, class T2> void re(pair<T1,T2>& p); inline bool blank(char c){ return (c == ' ' || c== '\t' || c== '\r' || c== '\n'); }; template<class T> void re(vector<T>& a); template<class T, size_t SZ> void re(array<T,SZ>& a); void re(int& x) { scanf("%d",&x);} void re(long& x) { scanf("%ld",&x);} void re(ll& x) { scanf("%lld",&x);} void re(unsigned& x) { scanf("%u",&x);} void re(unsigned long& x) { scanf("%lu",&x);} void re(unsigned long long& x) { scanf("%llu",&x); } void re(float& x) { scanf("%f",&x);} void re(double& x) { scanf("%lf",&x);} void re(ld& x) { scanf("%llf",&x);} bool re(char& x) { if(scanf("%c",&x)==EOF) return false; if(blank(x)) re(x); return true;} bool red(char& x) { if(scanf("%c",&x)==EOF) return false; return true; } void re(string& x) { char c;x=""; if(!re(c)) return; while(!blank(c)){ x+=c ; if(!red(c)) break;}} template<class T, class... Ts> void re(T& t, Ts&... ts) { re(t); re(ts...);} template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = {a,b}; } template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.ff,p.ss); } template<class T> void re(vector<T>& a) { fr(i,sz(a)) re(a[i]); } template<class T, size_t SZ> void re(array<T,SZ>& a) { fr(i,SZ) re(a[i]); } void pr(int x) { printf("%d",x ); } void pr(long x) { printf("%ld",x ); } void pr(ll x) { printf("%lld",x ); } void pr(unsigned x) { printf("%u",x ); } void pr(unsigned long x) { printf("%lu",x ); } void pr(unsigned long long x) { printf("%llu",x ); } void pr(float x) { printf("%.3f",x ); } void pr(double x) { printf("%.5lf",x ); } void pr(ld x) { printf("%.10llf",x ); } void pr(char x) { printf("%c",x ); } void pr(const char* x) { printf("%s",x ); } void pr(const string& x) { printf("%s",x.c_str()); } void pr(bool x) { pr(x ? "true" : "false"); } template<class T> void pr(const complex<T>& x) { cout << x; } template<class T1, class T2> void pr(const pair<T1,T2>& x); template<class T> void pr(const T& x); template<class T, class... Ts> void pr(const T& t, const Ts&... ts){pr(t); pr(ts...); } template<class T1, class T2> void pr(const pair<T1,T2>& x) { pr("(",x.ff,", ",x.ss,")"); } template<class T> void pr(const T& x) { pr("{");bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; pr("}");} void ps() { pr("\n"); } template<class T, class... Ts> void ps(const T& t, const Ts&... ts) { pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); } void pc() { pr("]\n"); } template<class T, class... Ts> void pc(const T& t, const Ts&... ts) { pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); } template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } vector<ll> fact; vector<ll> inv; ll mod = MOD; ll power(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll mod_inv(ll x) { return power(x, mod - 2); } ll nCr(ll n, ll r) { return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; } ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; } ll nHr(ll n, ll r) { return nCr(r + n - 1, r); } void comb_init(ll n, ll _mod = MOD) { mod = _mod; fact.resize(n + 1); fact[0] = 1; fr(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } inv.resize(n + 1); inv[n] = mod_inv(fact[n]); for (int i = n; i > 0; i--) { inv[i - 1] = inv[i] * i % mod; } } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rnd(ll x=0, ll y=INF) {return (rng() % (y-x +1)) + x;}; };using namespace amit; 

const int MX = 1e6 + 1000;



void solve(){
    int k; re(k);
    k++;
    ll ans = 0;
    fr(i,1,k){
        fr(j,1,k){
            fr(u,1,k){
                int g = __gcd(i,j) ; g = __gcd(g,u);
                ans+=g;
            }
        }
    }
    cout << ans << endl;


}
int main() {
    // int _ = 0; re(_); while(_--)
    solve();
}

Submission status: Runtime Error

Solution code:
N=int(input())
sum_gcd=0
for a_1 in range(1,N+1):
    for a_2 in range(1,N+1):
        for a_3 in range(1,N+1):
            sum_gcd+=gcd(a_1,a_2,a_3)
print(sum_gcd)

Submission status: Runtime Error

Solution code:
n=int(input())

total=0
for nn in range(1,n+1):
  for k in range(1,n+1):
    for l in range(1,n+1):
      total+=math.gcd(nn,math.gcd(k,l))

print(total)

Submission status: Runtime Error

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

def gcd2(num1,num2):
    if num2>num1:
        tem=num2
        num2=num1
        num1=tem
    
    if num1%num2==0:
        return num2
    else:
        gcd2(num1-num2,num2)
    

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

for n in range(1,num+1):
    for m in range(1,num+1):
        for l in range(1,num+1):
            sum=sum+gcd3(n,m,l)
            
print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np

#sys.setrecursionlimit(10 ** 9)

K = int(input())

def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

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

print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a%b)
def gcdt(a,b,c):
  return gcd(gcd(a,b),c)
s = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      s += gcdt(i,j,k)
print(s)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a%b)
def gcdt(a,b,c):
  return gcd(gcd(a,b),c)
s = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      s += gcdt(i,j,k)
print(gcd)

Submission status: Runtime Error

Solution code:


K = int(input())

ans = 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 i==k: g = i
            elif (i==j and i!=k):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (i==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (j==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            else : g = math.gcd(i,math.gcd(j,k))*6
            ans += g
print(ans)

Submission status: Runtime Error

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

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

print(gcd)

Submission status: Runtime Error

Solution code:
import math

K = int(input());
gcd = o;

for a in range(K):
  aa = a + 1 ;
  
  for b in range(K):
    bb = b + 1;
    
    for c in range(K):
      cc = c + 1;
      gcd += math.gcd(aa,bb,cc);
        
print(gcd)

Submission status: Runtime Error

Solution code:
from math import gcd

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

K = int(input())
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from sys import stdin
import itertools

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
def main:
  N = int(stdin.readline())
  N_list = list(range(1, N+1))
  
  ans = 0
  
  for xs in itertools.combinations_with_replacement(N_list, 3):
    if len(set(xs)) == 1:
      ans += gcd(xs[0], xs[1], xs[2])
    elif len(set(xs)) == 2:
      ans += 3*gcd(xs[0], xs[1], xs[2])
    else:
      ans += 6*gcd(xs[0], xs[1], xs[2])
      
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from sys import stdin
import itertools

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
def main:
  N = int(stdin.readline())
  N_list = lsit(range(1, N+1))
  
  ans = 0
  
  for xs in itertools.combinations_with_replacement(N_list, 3):
    if len(set(xs)) == 1:
      ans += 6*gcd(xs[0], xs[1], xs[2])
    elif len(set(xs)) == 2:
      ans += 3*gcd(xs[0], xs[1], xs[2])
    else:
      ans += gcd(xs[0], xs[1], xs[2])
      
  print(ans)

Submission status: Runtime Error

Solution code:
import math
K = int(input())
a = 1
SUM = 0
while a <= K:
    b=1
    while b<= K:
       c=1
       while c<= K:
           gcd_1 = math.gcd(a,b)
           gcd = math.gcd(gcd_1,c)
           SUM += gcd
           c+=1
        b+=1
    a+=1
print(SUM)

Submission status: Runtime Error

Solution code:
def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)



k = (int(x) for x in input().split())

n = 3
c = {} 
t = 0
for x in range(k, 0, -1):
    c[x] = (k // x) ** n
    c[x] = c[x] - sum(c[x * y] for y in range(2, k // x + 1))
    s = c[x] * x
    t += s
    # t = t % 1000000007

print(t)

Submission status: Runtime Error

Solution code:
def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)



k = (int(x) for x in input().split())

c = {} 
t = 0
for x in range(k, 0, -1):
    c[x] = (k // x) ** n
    c[x] = c[x] - sum(c[x * y] for y in range(2, k // x + 1))
    s = c[x] * x
    t += s
    # t = t % 1000000007

print(t)

Submission status: Runtime Error

Solution code:
def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)



n, k = (int(x) for x in input().split())

c = {} 
t = 0
for x in range(k, 0, -1):
    c[x] = (k // x) ** n
    c[x] = c[x] - sum(c[x * y] for y in range(2, k // x + 1))
    s = c[x] * x
    t += s
    t = t % 1000000007

print(t)

Submission status: Runtime Error

Solution code:
import math

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

sum = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools
def all_passwords(chars,length):
    b = []
    c= 0
    for i in itertools.product(int(chars), repeat=length):
        a = ''.join(i)
        b.append(a)
    return b
print (all_passwords(12,2))

Submission status: Runtime Error

Solution code:
K = int(input())

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

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

print(s)

Submission status: Runtime Error

Solution code:
from math import gcd
import numpy as np


def sum_gcd(k: int) -> int:
    # a > b > c
    sum_p1 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            for j in range(1, i):
                sum_p1 += gcd(h, i, j)
                
    # a = b > c
    sum_p2 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            sum_p2 += gcd(h, h, i)
    
    # a > b = c
    sum_p3 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            sum_p3 += gcd(h, i, i)

    # a = b = c
    sum_p4 = k * (k + 1) //2

    answer = sum_p1 * 6 + sum_p2 * 3 + sum_p3 * 3 + sum_p4

    return answer


def main():
    k = int(input().rstrip())
    print(sum_gcd(k))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import gcd
z=range(1,1+int(input()))
y=0
for a in z:
  for b in z:
    for c in z:
      y+=reduce(gcd,(a,b,c)
print(y)

Submission status: Runtime Error

Solution code:
from math import gcd
x=range(int(input()))
y=0
for a in z:
  for b in z:
    for c in z:
      y+=gcd(gcd(a+1,b+1),c+1)
print(y)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a<b:
        tmp = a
        a = b
        b = tmp
    r = a % b
    while r!=0:
      a = b
      b = r
      r = a % b
    return b
  
def main():
    K = int(input())
    list_ = []
    sum_ = 0
    for i in range(K):
        for j in range(K):
            a = gcd(i,j)
            list_.append(a)
    for i in list_:
        for j in range(K):
            a = gcd(i,j)
            sum_ += a
    print(sum_)

main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
sum = 0

def gcd_cal(a, b, c):
    d = math.gcd(a, b)
    return math.gcd(d, c)
}

K = int(input())

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            sum += gcd_cal(i, j, k)

print(str(sum))

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

print(ans)

Submission status: Runtime Error

Solution code:
from math import math

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

Submission status: Runtime Error

Solution code:
from math import gdc
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:
from math import gdc
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(l,j),i)

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
2.import math
3.K=int(input())
4.Kl=range(1,K+1)
5.L=list(itertools.product(Kl,Kl,Kl))
6. 
7.counter=0
8.for l in L:
9.  l=list(l)
10.  ans = l[0]
11.  for i in range(1,3):
12.    ans=math.gcd(ans, l[i])
13.  counter+=ans
14.print(counter)

Submission status: Runtime Error

Solution code:
import itertools
import math
K=int(input())
Kl=range(1,K+1)
L=list(itertools.product(Kl,K1,K1))

counter=0
for l in L:
  l=list(l)
  ans = l[0]
  for i in range(1,3):
    ans=math.gcd(ans, l[i])
  counter+=ans
print(counter)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
 
for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if N-1<k:
      break
 
    if S[j]!=S[i] and S[j]!=S[k] and S[k]!=S[i]:
        ans-=1
        
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

Submission status: Runtime Error

Solution code:
from math import gcd

def main():
    K=int(input())
    ans=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            p=gcd(a,b)
            if p==1:
                ans+=p*K
            else:
                for c in range(1,K+1):
                    ans+=gcd(p,c)

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    K = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    x_arr = np.arange(1,K+1)
    cnt = np.gcd.outer(np.gcd.outer(x_arr,x_arr),x_arr).sum()
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Runtime Error

Solution code:
import math

K = int(input()) + 1
d = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

c = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            a = math.gcd(math.gcd(i,j), l)
            c += b

print(c)

Submission status: Runtime Error

Solution code:
from functools import lru_cache
    @lru_cache(maxsize = None)
from math import gcd

def gcdx(x,y,z):
    return gcd(gcd(x,y),z)
n = int(input())
a = 0
longp = []

for i in range(1,n+1):
    for j in range(1,n+1):
        for p in range(1,n+1):
            a += gcdx(i,j,p)
           
print(a)

Submission status: Runtime Error

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

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i,j)
                ans = ans + gcd(ij,k)

print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b,c):
  min = a
  if b<a and b<c:
    min = b
  elif c<a and c<b:
    min = c
  
  if a%min==0 and b%min==0 and c%min==0:
    ans = min
  else:
    for i in range(2,min):
      if a%i==0 and b%i==0 and c%i==0:
        ans = i
  return(ans)
 
k = int(input())
sum = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      sum += gcd(a,b,c)
print(sum)

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
 def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
K = int(input())
t = 0
t1 = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            t1 = gcd(i,j)
            t = t + gcd(t1,l)
print(t)

Submission status: Runtime Error

Solution code:
import math
import fractions

k = input()

sum = 0
for a in range(k):
    for b in range(k):
        x = fractions.gcd(a+1, b+1)
        for c in range(k):
            y = fractions.gcd(x, c+1)
            sum += y
print(sum)

Submission status: Runtime Error

Solution code:
k=int(input())

from math import gcd
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=math.gcd(math.gcd(n,i),j)

print(res)

Submission status: Runtime Error

Solution code:
k=int(input())

import math
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=math.gcd(gcd(n,i),j)

print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

K = 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 = input()
sum = 0

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

print(sum)

Submission status: Runtime Error

Solution code:
import math

K = 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,d)

print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
R = []
G = []
B = []
for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    elif S[i] == 'B':
        B.append(i)
ans = len(R)*len(G)*len(B)
for i in range(1,(N+1)//2):
    for j in range(i,N-i):
        if S[j] != S[j-i] and S[j] != S[j+i] and S[j-i] != S[j+i]:
            ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
i = 1
j = 1
k = 1
ans = 0
while i < n+1:
    j = 1
    while j < n+1:
        k = 1
        p = gcd(i,j)
        while k < n+1:
            if (p-1)*(k-1) == 0:
                ans += 1
            else:
                ans += gcd(k,p)
            k += 1
        j += 1
    i += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# 最大公約数を格納するリストを初期化
max_codiv = []
 
# 繰り返す数を入力
n = int(input())
 
import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
    for j in range(1, n+1):
    	i_j = math.gcd(i, j)
        for k in range(1, n+1):
            i_j_k = math.gcd(i_j, k)
            max_codiv.append(i_j_k)
print(sum(max_codiv))

Submission status: Runtime Error

Solution code:
from functools import reduce

def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def mgcd(*a)
    return reduce(gcd, a)

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):
      tmp = mgcd(i, j, l)
      if i == j== k:
        ans += tmp
      else:
        ans += tmp*3
print(ans)

Submission status: Runtime Error

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

import math

K = int(input())
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
k = int(s)
n = 3
ans={}
for i in reversed(range(1, k+1)):
    ans[i]=math.floor(k/i)**n
    l=2
    j=i*l
    while j<=k:
        ans[i]=ans[i]-ans[j]
        l +=1
        j = i*l
res=0
for i in ans:
    res+=i*ans[i]
print(res)

Submission status: Runtime Error

Solution code:
s = input().split()
k = int(s[0])
n = 3
ans={}
for i in reversed(range(1, k+1)):
    ans[i]=math.floor(k/i)**n
    l=2
    j=i*l
    while j<=k:
        ans[i]=ans[i]-ans[j]
        l +=1
        j = i*l
res=0
for i in ans:
    res+=i*ans[i]
print(res)

Submission status: Runtime Error

Solution code:
s = input().split()
k = int(s[0])
n = 3
ans={}
for i in reversed(range(1, k+1)):
    # print(i*(math.floor(k/i))**n)
    ans[i]=math.floor(k/i)**n
    l=2
    j=i*l
    while j<=k:
        ans[i]=ans[i]-ans[j]
        l +=1
        j = i*l
res=0
for i in ans:
    res+=i*ans[i]
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import itertools
GCD_over_150=[4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]

N=int(input())
if N<150:
    GCD=[]
    GCD1=[]
    for i in range (1,N+1):
	    GCD.append(i)
    for i in itertools.product(GCD,repeat=3):
		GCD1.append(math.gcd(math.gcd(i[0],i[1]),i[2]))
	print(sum(GCD1))    
else:
    print(GCD_over_150[N-150])

Submission status: Runtime Error

Solution code:
K = int(input())

gcd = lambda a,b : a if b == 0 else gcd(b, a % b)
gcd3 = lambda a,b,c = gcd(c, gcd(a,b))

print(sum(list(map(lambda: x,y,z: gcd3(x,y,z), list(range(1,K+1))))))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
cdef gcd(a,b):
    if b<a:a,b=b,a
    r=b%a
    return a if r==0else gcd(a,r)
k=int(input())+1
print(sum(gcd(c,gcd(a,b))for a in range(1,k)for b in range(1,k)for c in range(1,k)))

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import math
N = int(input())
GCD = [[math.gcd(i, j) for i in range(1, 10)] for j in range(1, 10)]
all_gcd = [GCD[GCD[i][j]][m] for i in range(1, N+1) for j in range(1, N+1) for m in range(1, N+1)]
print(sum(all_gcd))

Submission status: Runtime Error

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


print(apt(K))

Submission status: Runtime Error

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


print(apt(K))

Submission status: Runtime Error

Solution code:
from itertools import permutations
a = int(input())
allval = []
def gcd(a, b, c):
    if a < b:
        if a < c:
            small = a
        else:
            small = b
    else:
        if b < c:
            small = b
        else:
            small = c
    hcf = small
    while hcf > 0:
        if a % hcf == 0 and b % hcf == 0 and c % hcf == 0:
            allval.append(hcf)
            break
        else:
            hcf -= 1
h = 5
def rec(x, y, z):
    if z <= a:
        gcd(x, y, z)
        rec(x, y, z+1)
    elif y < a:
        rec(x, y+1, 1)
    elif x < a:
        rec(x+1, 1, 1)
    

rec(1, 1, 1)
print(sum(allval))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def gcd(p, q):
    while (q != 0):
        r = p % q
        p = q
        q = r
    return p
K = int(input())
cnt = 0
for a in range(K):
    for b in range(K):
      g1 = 0
      g1 = gcd(a+1, b+1)
        for c in range(K):
            g2 = 0
            g2 = gcd(g1, c+1)
            cnt += g2
print(str(cnt))

Submission status: Runtime Error

Solution code:
N=int(input())
S=str(input())
list_R=[]
list_G=[]
list_B=[]
count=0
for i in range(N):
    if S[i]=="R":
        list_R.append(i)
    if S[i]=="G":
        list_G.append(i)
    if S[i]=="B":
        list_B.append(i)
for i in range(N):
    for j in range(N):
        if i+2*j>N-1:
            break
        if S[i]!=S[i+j] and S[i+j]!=S[i+j*2] and S[i+2*j]!=S[i]:
            count=count+1

print(len(list_B)*len(list_G)*len(list_R)-count)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

K = int(read())

x = np.arange(1, K + 1)
nums = np.gcd.outer(x, x, x)
print(nums.sum())