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):
k = int(input())

ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        for l in range(k + 1):
            for m in range(k, 0, -1):
                if i % m == 0 and j % m == 0 and l % m == 0:
                    ans += m
                    
print(ans)

k = int(input())

ans = 0
for i in range(1, k + 1):
    for j in range(1, i + 1):
        for l in range(1, j + 1):
            while True:
                p = i
                q = j
                r = p % q
                p = q
                q = r
                if q == 0:
                    break
                q = l
                r = p % q
                p = q
                q = r
                if q == 0:
                    ans += p
                    break
print(ans)


k = int(input())

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

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)

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
sum = 0
K = 2
for k in range(K):
  for j in range(K):
    for i in range(K):
      sum = sum + gcd(k+1,j+1,i+1)
      print(gcd(k,j,i))
print(sum)

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)

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

Verdicts: Runtime Error

Runtime Error

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):
import math

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

print(S)

from math import gcd 

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

print(S)

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

from math import gcd
K = int(input())
plus = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        temp = gcd(a, b)
        if temp != 1:
            for c in range(1, K+1):
                plus += gcd(temp, c)
        else:
            plus += K
print(plus)

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

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = fractions.gcd(i, j)
            b = fractions.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3


print(g)


import itertools
import fractions

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.product(K, repeat=3)
p = list(p)

g = []

for i in p:
    a = fractions.gcd(i[0], i[1])
    b = fractions.gcd(a, i[2])
    g.append(b)

print(sum(g))


import fractions

K = int(input())
g = []
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = fractions.gcd(i, j)
            b = fractions.gcd(a, k)
            if i != j != k:
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
            elif i == j == k:
                g.append(b)
            else:
                g.append(b)
                g.append(b)
                g.append(b)

print(sum(g))

import itertools
import fractions

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.product(K, repeat=3)
p = list(p)

g = []

for i in p:
    g.append(fractions.gcd(i[0], i[1]))

for i in range(len(g)):
    g[i] = fractions.gcd(g[i], p[i][2])

print(sum(g))

import itertools
import fractions

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.combinations_with_replacement(K, 3)
p = list(p)
g = []

for i in p:
    a = fractions.gcd(i[0], i[1])
    b = fractions.gcd(a, i[2])
    if i[0] != i[1] != i[2]:
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
    elif i[0] == i[1] == i[2]:
        g.append(b)
    else:
        g.append(b)
        g.append(b)
        g.append(b)


print(sum(g))


import math
import itertools

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.combinations_with_replacement(K, 3)
p = list(p)
g = 0

for i in p:
    a = math.gcd(i[0], i[1])
    b = math.gcd(a, i[2])
    if i[0] != i[1] != i[2]:
        g += b*6
    elif i[0] == i[1] == i[2]:
        g += b
    else:
        g += b*3

print(g)

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

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):
from math import gcd
k = int(input())
val = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for a in range(1,k+1):
      val+=gcd(i,gcd(j,a))

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


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

K = 200

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

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

print(ans)

import math
from functools import reduce

K = int(input())

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

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

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 fractions
from functools import reduce
K = int(input())

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

s = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if a == b and b == c:
                s += gcd(a,b,c)
            elif a == b or a == c or b == c:
                s += gcd(a,b,c) * 3
            else:
                s += gcd(a,b,c) * 6
print(s)


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

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

s = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if a == b and b == c:
                s += gcd(a,b,c)
            elif a == b or a == c or b == c:
                s += gcd(a,b,c) * 3
            else:
                s += gcd(a,b,c) * 6
print(s)


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

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)

from math import gcd

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 += gcd(i, gcd(j,m))
print(ans)

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):
K = int(input())
from fractions import gcd
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        tmp_gcd = gcd(i, j)
        for k in range(1, K + 1):
            ans += gcd(tmp_gcd, k)
print(ans)

import math
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):
            tmp_gcd = math.gcd(i, j)
            tmp_gcd = math.gcd(tmp_gcd, k)
            if i == j == k:
                ans += tmp_gcd
            elif i == j or i == k or j == k:
                ans += tmp_gcd * 3
            else:
                ans += tmp_gcd * 6
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):
def resolve():
    N = int(input())
    ans = []
    for i in range(1, N+1):
        for j in range(1, N+1):
            for p in range(1, N+1):
                count = [1]
                for q in range(2, min(i, j, p)+1):
                    if i%q == 0 and j%q == 0 and p%q == 0:
                        count.append(q)
                ans.append(count[-1])
    print(sum(ans))
resolve

def resolve():
    K = int(input())
    ans = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            for p in range(1, K+1):
                count = []
                for q in range(1, min(i, j, p)+1):
                    if i%q == 0 and j%q == 0 and p%q == 0:
                        count.append(q)
                ans.append(max(count))
    print(sum(ans))
resolve


def resolve():
    import math
    K = int(input())
    ans = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            for p in range(1, K+1):
                q = math.gcd(i, j)
                ans.append(math.gcd(q, p))
    print(sum(ans))
resolve()

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 mapint_inp():
    return map(int, input().split())

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

import math
from functools import reduce
import itertools

K = intinp()

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

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

print(ans)


def mapint_inp():
    return map(int, input().split())
 
def intinp():
    return int(input())
 
import math
import itertools
  
K = intinp()
 
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        ij = math.gcd(i, j)
        for k in range(1, K+1):
            ans += math.gcd(ij, 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):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
gcd_list=[]
i=int(input())
for x in range(i):
  for y in range(i):
    for z in range(i):
      gcd_list.append(gcd(x, y, z))
print(sum(gcd_list))
      
      

from math import gcd
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans_=gcd(i,j)
        for l in range(1,k+1):
            ans+=gcd(ans_,l)
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 numba import njit
from math import gcd

K = int(input())

@njit
def solve():
    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 numba import njit
from math import gcd

K = int(input())

@njit
def solve():
    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)
    return ans

print(solve())

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

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)

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)


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)


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)


from math import gcd

k = int(input())
ans = 0

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

Verdicts: 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):
from math import gcd
k = int(input())
ans = 0

for s in range(1,k+1):
	for t in range(1,k+1):
  		for u in range(1, k+1):
			ans += gcd(gcd(s,t),u)
print(ans)

from math import gcd
k = int(input())
ans = 0
 
for s in range(1,k+1):
  for t in range(1,k+1):
    for u in range(1, k+1):
      ans += gcd(gcd(s,t),u)
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):
def gcd(a, b):
    if b == 0 or b == 1:
        return b
    return gcd(b, a % b)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            for k in range(j + 1, N + 1):
                total += gcd(k, gcd(j, i))
    print(total)


@lru_cache(maxsize=10**5)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)



@lru_cache(maxsize=10**6)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)



import math
from functools import lru_cache

@lru_cache(maxsize=10**6)
def cached_gcd(i, j):
    return math.gcd(i, j)

if __name__ == '__main__':
    N = int(input())
    total = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = cached_gcd(j, i)
            for k in range(1, N + 1):
                total += cached_gcd(k, g)
    print(total)



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):
import itertools
a=int(input())
A=[]
for i in range(a):
    A.extend(str(i+1))

li=list(itertools.combinations_with_replacement(A, 3))
s = 0
for lis in li:
    a = int(lis[0])
    b = int(lis[1])
    c = int(lis[2])
    
    for i in range(min(a,b,c)):
        if a%(i+1) == 0 and b%(i+1) == 0 and c%(i+1) ==0:
            gcd = i+1
            if a==b and b==c:
                s = s + gcd
            elif a== b or b==c:
                s = s + 3*gcd
            else:
                s = s + 9*gcd
print(s)

a=int(input())
s =0
for i in range(a):
    for j in range(a):
        for k in range(a):
            for n in range(min(i,j,k)+1):
                if a%(n+1) == 0 and b%(n+1) == 0 and c%(n+1) ==0:
                    gcd = n+1
            s = s + gcd
print(s)

import math
from functools import reduce

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

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

import itertools
a=int(input())
A=[]
for i in range(a):
    A.append(str(i+1))

li=list(itertools.combinations_with_replacement(A, 3))
s = 0
for lis in li:
    a = int(lis[0])
    b = int(lis[1])
    c = int(lis[2])
    
    if math.gcd(b,c) == 1:
        gcd1 = 1
    else:
        gcd1 = gcd(a,b,c)
    
    if a==b and b==c:
        s = s + gcd1
    elif a==b or b==c:
        s = s + 3*gcd1
    else:
        s = s + 6*gcd1
print(s)

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):
K = int(input())

if K == 1:
  print(1)
  
def f(K):
  s =  0
  count = 0
  for i in range(2,K+1):
    if K % i != 1:
      s += i
      count += 1
  return 3*K + s - count  
  
else:
  ans = 0
  for i in range(2,K+1):
    ans += f(K)
  print(ans)

K = int(input())
 
import math

ans = 0
a = 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):
import math
N = int(input())
L = [4680225, 4806225, 4876132,4983108,5081415, 5192101, 5280120, 5414682, 5490193, 5586549,5682696, 5818120, 5910951, 6044601, 6125932, 6241626, 6369993, 6476209, 6561540, 6732588,6826435, 6961953, 7083840, 7210858, 7302369, 7448493, 7574128, 7725096, 7843815, 7965721, 8063628, 8269314, 8369401, 8521833, 8648604, 8803564, 8927955, 9094401, 9216532, 9367782, 9530025, 9698077, 9809424, 10015152, 10128823, 10273329, 10450116, 10634146, 10752537, 10963029, 11083816]
if N >= 150:
    print(L[N-150])
else:
  L = []
  res = 0
  for a in range(N):
      for b in range(N):
          L.append(math.gcd(a,b))
  for el in L:
      for c in range(N):
          res += math.gcd(el,c)
  print(res)

N = int(input())
L = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 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]
print(L[N-1])

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

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

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

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

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)

k = int(input())
from math import gcd

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(gcd(i,j), k)
print(ans)

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

import fractions
from functools import reduce


k = int(input())

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

k += 1
ans = 0


#    for j in range(i,k):
#        #print(i,j)

#            ans += gcd(i,j)
#        else:
#            ans += gcd(i,j)*6

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


print(ans)



import fractions
from functools import reduce


k = int(input())

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

k += 1
ans = 0

for i in range(1,k):
    for j in range(i,k):
        #print(i,j)
        if i == j:
            ans += gcd(i,j)
        else:
            ans += gcd(i,j)*6

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


print(ans)


import math
from functools import reduce


k = int(input())

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

k += 1
ans = 0

for i in range(1,k):
    for j in range(i,k):
        #print(i,j)
        if i == j:
            ans += gcd(i,j)
        else:
            ans += gcd(i,j)*6

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


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):
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(input())
ans=0
for numbers in itertools.combinations_with_replacement(range(1,k+1),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
print(ans)

import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(input())
ans=0
for numbers in itertools.combinations_with_replacement(range(1,k+1),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c and b!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
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):
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)


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)


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)


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 = gcd2(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)


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):
import fractions
K = int(input())
ans = 0
for i in range(1,K+1):
	for j in range(1,K+1):
		for n in range(1,K+1):
			tmp = fractions.gcd(i,j)
			ans += fractions.gcd(tmp,n)
print(ans)

import math
K = int(input())
ans = 0
for i in range(1,K+1):
	for j in range(1,K+1):
		tmp = math.gcd(i,j)
		for n in range(1,K+1):
			ans += math.gcd(tmp,n)
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 math
k = int(input())
box = []
for i in range(1,k+1):
  for j in range(1,k+1):
    gap = math.gcd(i,j)
    if gap == 1:
      box.append(1*k)
    else:
      for l in range(1,k+1):
        gap2 = math.gcd(gap,l)
        box.append(gap2)        
print(sum(box))
print(box)

import math
k = int(input())
box = []
for i in range(1,k+1):
  for j in range(1,k+1):
    gap = math.gcd(i,j)
    if gap == 1:
      box.append(1*k)
    else:
      for l in range(1,k+1):
        gap2 = math.gcd(gap,l)
        box.append(gap2)        
print(sum(box))


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


import math
k = int(input())
total = 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):
            g2 = math.gcd(g1, c)
            total += g2
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):
import math

K = int(input())
res = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            tmp = math.gcd(i, j)s
            res += math.gcd(tmp, k)

print(res)

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: 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 as np
K=int(input())
s=0
d=0
for a in range(1,K+1):
    if a%2==0:
        for b in range(2,K+1,2):
            if a>b:
                if a%b==0:
                    d=b
                else:
                    d=np.gcd(a%b,b)
            if a<b:
                if b%a==0:
                    d=a
                else:
                    d=np.gcd(b%a,a)
            if a==b:
                d=a
            for c in range(2,K+1,2):
                if c>d:
                    if c%d==0:
                        s+=d
                    else:
                        s+=np.gcd(c%d,d)
                if c<d:
                    if d%c==0:
                        s+=c
                    else:
                        s+=np.gcd(d%c,c)
                if c==d:
                    s+=c
    if a%2==1:
        for b in range(1,K+1,2):
            if a>b:
                if a%b==0:
                    d=b
                else:
                    d=np.gcd(a%b,b)
            if a<b:
                if b%a==0:
                    d=a
                else:
                    d=np.gcd(b%a,a)
            if a==b:
                d=a
            for c in range(1,K+1,2):
                if c>d:
                    if c%d==0:
                        s+=d
                    else:
                        s+=np.gcd(c%d,d)
                if c<d:
                    if d%c==0:
                        s+=c
                    else:
                        s+=np.gcd(d%c,c)
                if c==d:
                    s+=c
    if K%2==0:
        s+=K**3-(K//2)**3-(k//2+1)**3
    else:
        s+=K**3-(K//2)**3-(k//2)**3
print(s)


import math as np
K=int(input())
s3=0
s2=0
s1=0
s0=0
for a in range(1,K-1):
    for b in range(a+1,K):
        d=np.gcd(a,b)
        for c in range(b+1,K+1):
            s0+=np.gcd(c,d)
for a in range(1,K):
    for c in range(a+1,K+1):
        s1+=np.gcd(a,c)
for a in range(1,K):
    for b in range(a+1,K+1):
        s3+=np.gcd(a,b)
for k in range(K+1):
    s2+=k
print(s0*6+s1*3+s3*3+s2)
        

            

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_list = list()
"""
def gcd(a, b):
    if b==0:
        return a
    else:
        return gcd(b, a % b)
"""
for X in range(1, K+1):
    ans = 0
    for i in range(1, X+1):
        for j in range(1, X+1):
            tmp = gcd(i, j)
            if tmp == 1:
                ans += tmp*X
            else:
                for k in range(1, X+1):
                    ans += gcd(tmp, k)
                
    print(X, ans)
    ans_list.append(ans)
        
print(ans_list)


from math import gcd

K = int(input())


ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        if tmp == 1:
            ans += tmp*K
        else:
            for k in range(1, K+1):
                ans += gcd(tmp, 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)
    
k = int(input())
sum = 0
for a in xrange(1,k+1):
    for b in xrange(1,k+1):
        for c in xrange(1,k+1):
            sum += gcd(a,b,c)
print(sum)

import math

k = int(input())
a = []
result = []

for i in range(1,k+1):
    for j in range(1,k+1):
        a.append(math.gcd(i,j))

for i in range(1,k+1):
    result.extend(math.gcd(n,i) for n in a)

print(sum(result))

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

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

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
import itertools
k = int(input())

result = 0


for i in range(1, k+1):
    result += i


for set in list(itertools.combinations(range(1, k+1), 2)):
    result += (gcd(set[0], set[1]))*6


for set in list(itertools.combinations(range(1, k+1), 3)):
    result += (gcd(gcd(set[0], set[1]), set[2]))*6

print(result)

from fractions import gcd
k = int(input())
result = 0


for i in range(1, k+1):
    for j in range(i, k+1):
        for m in range(j, k+1):
            if i==j==m:
                result += i
            elif i==j or j==m:
                result += gcd(i, m)*3
            else:
                result += gcd(i, gcd(j,m))*6
print(result)

from fractions import gcd
import itertools
k = int(input())

result = 0


for i in range(1, k+1):
    result += i


for i in range(1, k+1):
    liste = list(range(1, k+1))
    liste.pop(i-1)
    for j in liste:
        result += (gcd(i, j))*3


for set in list(itertools.combinations(range(1, k+1), 3)):
    result += (gcd(gcd(set[0], set[1]), set[2]))*6

print(result)



from math import gcd
import itertools
k = int(input())
 
result = 0
 

for i in range(1, k+1):
    result += i
 

for set in list(itertools.combinations(range(1, k+1), 2)):
    result += (gcd(set[0], set[1]))*6
 

for set in list(itertools.combinations(range(1, k+1), 3)):
    result += (gcd(gcd(set[0], set[1]), set[2]))*6
 
print(result)

Verdicts: Time Limit Exceeded

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 gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
k=int(input())
count=0
for a in range(k):
  for b in range(k):
    for c in range(k):
      count+=gcd(gcd(a,b),c)
print(count)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
k=int(input())
count=0
count+=k*(k+1)//2
for i in range(1,k+1):
  for j in range(1,k+1):
    if i!=j:
      count+=3*gcd(i,j)
for a in range(1,k+1):
  for b in range(a+1,k+1):
    for c in range(b+1,k+1):
      count+=6*gcd(gcd(a,b),c)
print(count)

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
from itertools import permutations

k = int(input())
ans = 0

for i in range(1, k+1):
    for j in range(i, k+1):
        for l in range(j, k+1):
            dup = len(set([i, j, l]))
            if dup == 1:
                num = 1
            elif dup == 2:
                num = len(list(permutations([i, j, l]))) / 2
            else:
                num = len(list(permutations([i, j, l])))
            ans += gcd(i, gcd(j, l)) * num

print(ans)


from math import gcd
from itertools import permutations

k = int(input())
ans = 0

for i in range(1, k+1):
    for j in range(i, k+1):
        for l in range(j, k+1):
            dup = len(set([i, j, l]))
            if dup == 1:
                num = 1
            elif dup == 2:
                num = len(list(permutations([i, j, l]))) / 2
            else:
                num = len(list(permutations([i, j, l])))
            ans += gcd(i, gcd(j, l)) * num

print(int(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):
#C
import math
l=12
m=4
n=8
def gcd_great(l,m,n):
    p=math.gcd(l,m)
    q=math.gcd(p,n)
    return q

k=int(input())
gcd_list=[]
for h in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):
            gcd_num=gcd_great(h,i,j)
            gcd_list.append(gcd_num)
sum(gcd_list)

#C
import math

def gcd_great(l,m,n):
    p=math.gcd(l,m)
    q=math.gcd(p,n)
    return q

k=int(input())


gcd_sum=0
for i in range(1,k+1):
    for j in range(1,k+1):
        if i!=j:
            g=math.gcd(i,j)
            gcd_sum=gcd_sum+g*3


for a in range(1,k-1):
    for b in range(a+1,k):
            for c in range(b+1,k+1):
                gcd_sum+=gcd_great(a,b,c)*6
gcd_sum+=int((k+1)*k*(1/2))

print(gcd_sum)

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

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)

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(l,j),i)
 
print(ans)

Verdicts: 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 math import gcd as g


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


print(ans)




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




from math import gcd as g

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


print(ans)




from math import gcd as g


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


print(ans)


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):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


K = int(input())

sum_gcd = 0
cand = itertools.combinations(K, 3))
for i in range(1, K + 1):
    for j in range(1, K + 1):
        g=gcd(i, j)
        for k in range(1, K + 1):
            sum_gcd += gcd(g, k)
print(sum_gcd)

import functools
import itertools


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


def gcd(nums):
    return functools.reduce(euclid, nums)


K = int(input())

sum_gcd = 0
cand = list(itertools.combinations_with_replacement(range(1, K + 1), 3))
for nums in cand:
    sum_gcd += gcd(nums)
print(sum_gcd)


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


K = int(input())

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

Verdicts: 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):
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):
        d = gcd(a, b)
        for c in range(1, k+1):
            ans += gcd(d, c)
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 math
from functools import reduce
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):
            nums = [a, b, c]
            gcd = reduce(math.gcd, nums)
            print(a, b, c, gcd)
            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):
        p = gcd(a, b)
        for c in range(1, K+1):
            sum += gcd(p, c)
print(sum)

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):
# P3:
def get_gcd(numbers):
    """Helper function to get GCD of list of numbers."""
    import math
    from functools import reduce

    if 1 in numbers:
        return 1

    # gcd is associative
    return reduce(lambda x, y: math.gcd(x, y), numbers)


def sum_of_gcd_tuples():
    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 += get_gcd([a, b, c])

    print(total)

def sum_of_gcd_tuples():
    from math import gcd
    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(gcd(a, b), c)

    print(total)


sum_of_gcd_tuples()

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(sys.stdin.readline().rstrip())

def gcd(a,b):

    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

cnt1 = 0
cnt2 = 0
cnt3 = 0
for n1 in range(K):
    for n2 in range(K):
        temp = gcd(n1+1, n2+1)
        for n3 in range(K):
            cnt3 += gcd(temp, n3+1)
        

ans = cnt1 + cnt2 + cnt3
print(ans)

import sys

K=int(sys.stdin.readline().rstrip())
 
def gcd(a,b):

    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

cnt1 = 0
cnt2 = 0
cnt3 = 0
for n1 in range(0,K):
    cnt1 += n1+1
    for n2 in range(n1+1, K):
        temp = gcd(n1+1, n2+1)
        cnt2 += temp*6
        for n3 in range(n2+1, K):
            cnt3 += gcd(temp, n3+1)*6
        

ans = cnt1 + cnt2 + cnt3
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())
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)

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

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

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)

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


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted