TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
import copy
K=200
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)


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)


n = int(input())
 
from math import gcd
 
y = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        x = gcd(i, j)
        for k in range(1, n+1):
            y += gcd(x,k)
 
print(y)

Verdicts: Time Limit Exceeded

Runtime Error

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

Submission attempts (in order):
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)

import math

K = int(input())

sum = 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 += np.gcd(n, c)
print(sum)

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)

from math import gcd

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
ans = 0
k = 2
def f(x,y):
  x,y= min(x,y),max(x,y)
  while y%x != 0:
    z = y%x
    y = x
    x = z
  else:
    return x
def ff(a,b,c):
  return f(c,f(a,b))
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            c = sorted([i,j,k])
            print(c)
            ans += ff(c[0],c[1],c[2])
print(ans)

ans = 0
k = int(input())
def f(x,y):
  x,y= min(x,y),max(x,y)
  while y%x != 0:
    z = y%x
    y = x
    x = z
  else:
    return x
def ff(a,b,c):
  return f(c,f(a,b))
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            c = sorted([i,j,k])
            print(c)
            ans += ff(c[0],c[1],c[2])
print(ans)

ans = 0
k = int(input())
def f(x,y):
  x,y= min(x,y),max(x,y)
  while y%x != 0:
    z = y%x
    y = x
    x = z
  else:
    return x
def ff(a,b,c):
  return f(c,f(a,b))
for i in range(1,k+1):
    for j in range(i,k+1):
        for k in range(j,k+1):
            if i == j == k:
              ans += ff(i,j,k)
            elif (i == j) or (j == k):
                ans += 3*ff(i,j,k)
            else:
                ans += 6*ff(i,j,k)            
print(ans)

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
a=int(input())
import math
print(sum(gcd(gcd(i,j),k)for i in range(1,a+1) for j in range(1,a+1) for k in range(1,a+1)))

a=int(input())
import math
print(sum(math.gcd(math.gcd(i,j),k)for i in range(1,a+1) for j in range(1,a+1) for k in range(1,a+1)))

Verdicts: Runtime Error

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

Submission attempts (in order):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10 ** -7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


def gcd_3(x, y, z):
    return gcd(gcd(x, y), z)

K = inp()


ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            a = gcd_3(i, j, k)
            if i == j == k:
                ans += a
            elif i == j or j == k:
                ans += a * 3
            else:
                ans += a * 3 * 2
print(ans)


from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd
 
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10 ** -7
 
def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))
 
def lcm(x, y): return (x * y) // gcd(x, y)
 
 
def gcd_3(x, y, z):
    return gcd(gcd(x, y), z)
 
K = inp()
 

ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            a = gcd_3(i, j, k)
            if i == j == k:
                ans += a
            elif i == j or j == k:
                ans += a * 3
            else:
                ans += a * 3 * 2
print(ans)

from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from math import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10 ** -7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


K = inp()

def gcd_3(x, y, z):
    return gcd(gcd(x, y), z)

dic = {} 
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        # tmp = gcd(i, j)
        for k in range(j, K + 1):
            # a = gcd(tmp, k)
            # a = gcd(gcd(i, j), k)
            a = gcd_3(i, j, k)
            if i == j == k:
                ans += a
            elif i == j or j == k:
                ans += a * 3
            else:
                ans += a * 3 * 2
print(ans)


Verdicts: Time Limit Exceeded

Time Limit Exceeded

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

Submission attempts (in order):
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)

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)

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)

import itertools
import math
import functools
import scipy.special

k = int(input())
def sum_of_gcd(k, n):
    t = 0
    for i in range(1, 4):
        c = itertools.combinations(range(1, k + 1), i)
        cc = map(lambda x: functools.reduce(math.gcd, x), c)
        c2 = scipy.special.comb(k, i - 1, exact=True)
        s = sum(cc) * c2
        t += s
print(sum_of_gcd(k, 3))



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)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

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

Submission attempts (in order):
import fractions

K = input()

Sum = 0
k = int(K)

for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = fractions.gcd(a, b)
        for C in range(k):
            c = C + 1

            Sum = Sum + fractions.gcd(gcd_ab, c)

print(Sum)

import fractions

K = input()

Sum = 0

for A in range(K):
    a = A + 1
    for B in range(K):
        b = B + 1
        for C in range(K):
            c = C + 1

            Sum = Sum + fractions.gcd(fractions.gcd(a, b), c)

print(Sum)

import fractions

K = input()

Sum = 0

for A in range(int(K)):
    a = A + 1
    for B in range(int(K)):
        b = B + 1
        for C in range(int(K)):
            c = C + 1

            Sum = Sum + fractions.gcd(fractions.gcd(a, b), c)

print(Sum)

import math
 
K = input()
 
Sum = 0
k = int(K)
 
for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = math.gcd(a, b)
        for C in range(k):
            c = C + 1
 
            Sum = Sum + math.gcd(gcd_ab, c)
 
print(Sum)

Verdicts: Time Limit Exceeded

Runtime Error

Time Limit Exceeded

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

Submission attempts (in order):
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [6, 3, 1]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    print(time.time() - s)


import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [6, 3, 1]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    # print(time.time() - s)


import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [1, 3, 6]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    print(time.time() - s)


import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [1, 3, 6]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


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


if __name__ == '__main__':
    s = time.time()
    main()
    # print(time.time() - s)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import math
ans=0
k=int(input())
for i in range(k):
  for j in range(k):
    gcd_ij=math.gcd(i+1,j+1)
    for k in range(k):
      ans+=math.gcd(gcd_ij,k+1)
print(ans)
      

import math
k=int(input())
#print(k)
ans_list=[]
for i in range(1,k+1):
  for j in range(1,k+1):
    gcd_ij=math.gcd(i,j)
    
    for k in range(1,k+1):
      ans_list.append(math.gcd(gcd_ij,k))
      #print(ans_list)
print(sum(ans_list))

Verdicts: Wrong Answer

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

Submission attempts (in order):
def gcd(a, b):
  if a < b:
    a, b = b, a
  while a % b:
    a, b = b, a % b
  return b

k = int(input())
total = 0
for a in range(1, k-1):
  for b in range(a, k):
    for c in range(b, k+1):
      if a == b == c:
        total += gcd(gcd(a, b), c)
      elif a == b or b == c:
        total += 3*gcd(gcd(a, b), c)
      else:
        total += 6*gcd(gcd(a, b), c)
print(total)

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)

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

k = int(input())
total = 0
for a in range(1, k+1):
  for b in range(a, k+1):
    for c in range(b, k+1):
      if a == b == c:
        total += gcd(gcd(a, b), c)
      elif a == b or b == c:
        total += 3*gcd(gcd(a, b), c)
      else:
        total += 6*gcd(gcd(a, b), c)
print(total)


Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
# 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)

# 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)

Verdicts: Runtime Error

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

Submission attempts (in order):
import fractions
from functools import reduce

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

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)

import math
ans = 0
n = int(input())

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


Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
k = int(input())

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

total = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            if (a%b==0 or b%a==0) and (b%c==0 or c%b==0) and (c%a==0 or a%c==0):
                total += 1
            else:
                total += gcd(a,b,c)
print (total)


k = int(input())

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

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
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)



K = int(input())

import math

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

print(ans)


Verdicts: Runtime Error

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

Submission attempts (in order):
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)

import math
K=int(input())
c=0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      a=math.gcd(i,j)
      b=math.gcd(a,k)
      if i==j==k:
        c+=b
      elif i==j or j==k:
        c+=3*b
      else:
        c+=6*b
print(c)

Verdicts: Runtime Error

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

Submission attempts (in order):
n = int(input())
ans = 0
t = 0
import fractions
for i in range(1,n+1):
  for j in range(1,n+1):
    t = fractions.gcd(i,j)
    for k in range(1,n+1):
      ans += fractions.gcd(t,k)
print(ans)

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



Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
k = int(input())
import fractions
ans = 0
for i in range(1,k+1):
         for j in range(i,k+1):
                  for l in range(j,k+1):
                           tmp = fractions.gcd(i,j)
                           tmp = fractions.gcd(tmp,l)
                           if i == j == l:
                                    ans += tmp
                           elif i == j or j == l or l == i:
                                    ans += 3 * tmp
                           else:
                                    ans += 6 * tmp
print(ans)


k = int(input())
import math
ans = 0
for i in range(1,k+1):
         for j in range(i,k+1):
                  for l in range(j,k+1):
                           tmp = math.gcd(i,j)
                           tmp = math.gcd(tmp,l)
                           if i == j == l:
                                    ans += tmp
                           elif i == j or j == l or l == i:
                                    ans += 3 * tmp
                           else:
                                    ans += 6 * tmp
print(ans)


Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
import sys
import numpy as np

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

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




import sys
import numpy as np

N=int(input())
count = 0

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

print(count)

import sys
import numpy as np

N=int(input())
count = 0

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

print(count)

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
def main():
    from math import gcd

    K=int(input())
    cal=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            i=gcd(a,b)

        for c in range(1,K+1):
            cal+=gcd(i,c)

    print(cal)


main()


def main():
    from math import gcd

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

    print(cal)


main()


Verdicts: Wrong Answer

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

Submission attempts (in order):
from math import gcd

k = 200
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)


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


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)


from math import gcd

k = int(input())
total = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        t = gcd(a, b)
        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


Verdicts: Wrong Answer

Runtime Error

Runtime Error

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

Submission attempts (in order):
from fractions import gcd
k = int(input())
ans = 0
for a in range(1,k+1):
	for b in range(a+1,k+1):
		for c in range(b+1,k+1):
			ans += gcd(gcd(a,b),c)

print(ans*3)

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

print(ans)

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

print(ans)

Verdicts: Wrong Answer

Time Limit Exceeded

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

Submission attempts (in order):
K = int(input())

result = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            max_abc = max([a,b,c])
            print(a,b,c)
            for i in range(max_abc, 0, -1):
                if (a%i == 0 and b%i == 0) and c%i == 0:
                    result += i
                    break
print(result)

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 += gcd * coef
print(result)

Verdicts: Wrong Answer

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

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

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

from math import gcd
ans=0
K=int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    if abs(i-j)==1 or j==1 or i==1:
      a=1
    else:
      a=gcd(i,j)
    for k in range(1,K+1):
        if a==1:
            ans+=K
            break
        elif abs(a-k)==1:
            ans+=1
        else:
            ans+=gcd(a,k)
print(ans)

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
from math import gcd

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

from math import gcd

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
import math
from functools import reduce

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

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


import math
from functools import reduce

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

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



import math
from functools import reduce

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

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

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

print(sum)


import math
from functools import reduce

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

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

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


from math import gcd

K = int(input())
#K = 200
sum = 0

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

print(sum)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

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

Submission attempts (in order):
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)

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)

Verdicts: Runtime Error

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

Submission attempts (in order):
from math import gcd
K=int(input())+1
sum=0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            gcd1 = int(gcd(a,b))
            gcd2 = int(gcd(b,c))
            gcd = int(gcd(gcd1,gcd2))

            sum = sum+gcd
print(sum)

from math import gcd

K = int(input())
out = 0
Count = [0]*K
gcds = [[0]*K for i in range(K)]

for i in range (1,K+1):
    for j in range(1,+K+1):
        value = gcd(i,j)
        gcds[i-1][j-1]=value
        Count[value-1]+=1

for i in range(1,K+1):
    for j in range(1,K+1):
        out +=gcds[i-1][j-1]*Count[j-1] 
        
print(out)

Verdicts: Runtime Error

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

Submission attempts (in order):
import itertools
import fractions

N = input()
N = int(N)

l = list(itertools.combinations_with_replacement(list(range(1,N+1)), 3))
s_all = 0
for nums in l:
    count = 0
    ans = nums[0]
    for i in range(1, 3):
        ans = fractions.gcd(ans, nums[i])
    a,b,c = nums[0], nums[1], nums[2]
    if a==b:
        count+=1
    if a==c:
        count+=1
    if b==c:
        count+=1

    if count==0:
        num = 6
    elif count==1:
        num=3
    elif count==3:
        num=1
    s_all += ans*num
print(s_all)


import itertools
import fractions
import functools

N = input()
N = int(N)

l = list(itertools.combinations_with_replacement(list(range(1,N+1)), 3))
s_all = 0

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def gcd(nums):
    return functools.reduce(euclid, nums)

for nums in l:
    count = 0
    # ans = nums[0]
    
    #     ans = fractions.gcd(ans, nums[i])
    # ans = list(map(int, input().split()))
    ans = gcd(nums)
    a,b,c = nums[0], nums[1], nums[2]
    if a==b:
        count+=1
    if a==c:
        count+=1
    if b==c:
        count+=1

    if count==0:
        num = 6
    elif count==1:
        num=3
    elif count==3:
        num=1
    s_all += ans*num
print(s_all)


Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
import math
K = int(input())
tmp = 0
cnt = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = math.gcd(a, b)
        cnt = sum([math.gcd(tmp, c) for c in range(1, K+1)])
print(cnt)

import math
K = int(input())
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = math.gcd(a, b)
        cnt = sum([math.gcd(tmp, c) for c in range(1, K+1)])
print(cnt)

import math
K = int(input())
tmp = 0
cnt = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = math.gcd(a, b)
        cnt += sum([math.gcd(tmp, c) for c in range(1, K+1)])
print(cnt)


Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import math
from functools import reduce

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

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

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

import math
from functools import reduce

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

K = int(input())
three = 0
six = 0
same = 0
for a in range(1,K+1):
  for b in range(a, K+1):
    for c in range(b, K+1):
      if(a != b and b != c and a != c):
        six += gcd(a,b,c)
      elif(a == b and b == c and c == a):
        same += a
      else:
        three += gcd(a,b,c)

print(six * 6 + three * 3 + same) 

Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
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)


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


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


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)


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


k = int(input())
list=[]
import math import gcd

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)


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


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

ans = sum(list)
print(ans)


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


k = int(input())
list=[]
import math import gcs

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)


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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
import math
l = int(input())
s = 0
for i in range(l):
  for j in range(l):
    t = math.gcd(i,j)
    for k in range(l):
      s += math.gcd(t,k)
print(s)

import math
l = int(input())
s = 0
for i in range(1,l+1):
  for j in range(1,l+1):
    t = math.gcd(i,j)
    for k in range(1,l+1):
      s += math.gcd(t,k)
print(s)

Verdicts: Wrong Answer

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

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

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

Submission attempts (in order):
import itertools
from fractions import gcd
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += gcd(gcd(a, b), c) * 6
        
print(ans)

import itertools
from fractions import gcd
 
K = int(input())
l = range(1, K+1)
ans = 0
 
for a, b, c in itertools.combinations_with_replacement(l, 3):
    if a == b and b == c:
        ans += a
    elif a == b or b ==c:
        ans += gcd(a, c) * 3
    else:
        ans += gcd(gcd(a, b), c)
        
 
print(ans)

import itertools
from fractions import gcd
 
K = int(input())
l = range(1, K+1)
ans = sum(range(1, K+1))
 
for a, b in itertools.combinations(l, 2):
    g = gcd(a, b)
    for c in l:
        if a == c or b == c:
            ans += g * 3
        else:
            ans += gcd(g, c) * 6
        
 
print(ans)

import itertools
from fractions import gcd

K = int(input())
l = range(1, K+1)
ans = 0

for a, b, c in itertools.product(l, repeat=3):
    ans += gcd(gcd(a, b), c)

print(ans)


import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += math.gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += math.gcd(math.gcd(a,b), c)*6
    
        
print(ans)

Verdicts: Time Limit Exceeded

Wrong Answer

Wrong Answer

Time Limit Exceeded

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

Submission attempts (in order):
from sys import stdin
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:return y
    else:
        while(x%y!=0):
            z=x%y
            x=y
            y=z
        return z

K = list(map(int, (stdin.readline().strip().split())))[0]
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:
                ans+=gcd(i,gcd(j,k))*3
                ij=True
print(ans)

from sys import stdin
import itertools
from math import gcd

#     x=max(a,b)
#     y=min(a,b)

#     else:
#         while(x%y!=0):

#             x=y
#             y=z


# K = list(map(int, (stdin.readline().strip().split())))[0]
# i=[x for x in range(1,K+1)]
# j=[x for x in range(1,K+1)]
# k=[x for x in range(1,K+1)]
# num_list=set(map(tuple,(sorted(x) for x in (itertools.product(i,j,k)))))
#
# ans=0
# for i,j,k in num_list:

#         if j==k:
#             ans+=K
#         else:
#             ans+=gcd(i,gcd(j,k))*3
#     elif j==k:ans+=gcd(i,gcd(j,k))*3
#     else:ans+=gcd(i,gcd(j,k))*6
K = int(input())

ans = 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)
            ans += a
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 21:45:38 2020

@author: H_Hoshigi
"""

import math

K = 200#int(input())

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



# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 22:01:05 2020

@author: H_Hoshigi
"""

import math

K = 200#int(input())
answer = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        gcd_a_b = math.gcd(a, b)
        for c in range(1, K+1):
            answer += math.gcd(gcd_a_b, c)
print(answer)



# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 22:01:05 2020

@author: H_Hoshigi
"""

import math

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



Verdicts: Time Limit Exceeded

Wrong Answer

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

Submission attempts (in order):
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)

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(K):
    tmp = gdc(b+1, a+1)
    for c in range(K):
      total += gdc(c+1, tmp)
print(total)


Verdicts: Runtime Error

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

Submission attempts (in order):
from math import gcd
K=int(input())
ans = 0
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            ans += gcd(gcd(a,b),c)
print(ans)

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
from fractions import gcd
k=int(input())
ans=0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      ans+=gcd(p,gcd(q,r))
print(ans)

from math import gcd
k=int(input())
ans=0
for p in range(1,k+1):
  for q in range(1,k+1):
    for r in range(1,k+1):
      ans+=gcd(p,gcd(q,r))
print(ans)

Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
k = int(input())

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

import math
k = int(input())

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

print(ans)

Verdicts: Runtime Error

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

Submission attempts (in order):
import fractions
from functools import reduce

k = int(input())

result = 0

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

for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            if a == b == c:
                result += a
            elif a == b and a!= c:
                result += gcd(a, c)*3
            elif a == c and a != b:
                result += gcd(a, b)*3
            elif b == c and a != b:
                result += gcd(a, b)*3
            else:
                result += gcd(a, b, c)*6
print(result)

import math
from functools import reduce

k = int(input())

result = 0

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

for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            if a == b == c:
                result += a
            elif a == b and a!= c:
                result += gcd(a, c)*3
            elif a == c and a != b:
                result += gcd(a, b)*3
            elif b == c and a != b:
                result += gcd(a, b)*3
            else:
                result += gcd(a, b, c)*6
print(result)

Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
# ABC 162

# https://note.nkmk.me/python-gcd-lcm/
A = int(input())

ans = 0
from fractions import gcd
from functools import reduce

def Ngcd(*numbers):
    return reduce(gcd, numbers)
d = dict()

for i in range(1,A+1):
    for j in range(1,A+1):
        for k in range(1,A+1):
            tmp = ','.join(list(map(str,sorted([i,j,k]))))
            if tmp in d.keys():
                ans +=d[tmp]
            else:
                min_bai = Ngcd(i,j,k)
                d[tmp] = min_bai
                ans += min_bai
print(ans)

# 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)

A = int(input())

ans = 0
from math import gcd


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)

Verdicts: Time Limit Exceeded

Runtime Error

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

Submission attempts (in order):
#C

K=int(input())+1



def pront(*n):
    if debug==1:
        print(n)
        
debug=1


import math as m

Z=[ [ [-1 for i in range(K)] for j in range(K)] for l in range(K)]
def C_1(i,j,k):
    xx=[i,j,k]
    xx.sort()
    if Z[xx[0]][xx[1]][xx[2]]!=-1:
        return Z[xx[0]][xx[1]][xx[2]]
    else:
        Z[xx[0]][xx[1]][xx[2]]=m.gcd(m.gcd(xx[0],xx[1]),xx[2])
        return Z[xx[0]][xx[1]][xx[2]]


x=0
for i in range(1,K):
    for j in range(1,K):
        if m.gcd(i,j)==1:
            x+=K
        else:
            for k in range(1,K):
                x+=C_1(i,j,k)
print(x)

#C

K=int(input())



def pront(*n):
    if debug==1:
        print(n)
        
debug=1


import math as m
Z=[ [-1 for i in range(K+1)] for j in range(K+1)]
def C_1(i,j):
    if Z[i][j]!=-1:
        return Z[i][j]
    else:
        x=m.gcd(i,j)
        Z[i][j]=x
        Z[j][i]=x
        return Z[i][j]

x=0
for i in range(1,K+1):
    for j in range(1,K+1):
        y=C_1(i,j)
        if y==1:
            x+=K
        else:
            for k in range(1,K+1):
                x+=C_1(y,k)
print(x)

Verdicts: Wrong Answer

Accepted