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 math
sum = 0
k = int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    for m in range(1,k+1):
      print(i,j,m)
      l = math.gcd(i,j)
      sum += math.gcd(l,m)
print(sum)

import math
sum = 0
k = int(input())
for i in range(1,k+1):
  for j in range(1,k+1):
    if i <= j:
      for m in range(1,k+1):
        if j <= m:
          if i==j==m:
            l = math.gcd(i,j)
            sum += math.gcd(l,m)
          elif i==j or j==m or m==i:
            l = math.gcd(i,j)
            sum += 3*(math.gcd(l,m))
          else:
            l = math.gcd(i,j)
            sum += 6*(math.gcd(l,m))
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):
from functools import reduce
from itertools import product

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

def gcd_list(A): return reduce(gcd, A)

K = int(input())
S = K * (K + 1) // 2
for a, b in combinations(range(1, K+1), 2):
    S += 6 * gcd(a, b)
for a, b, c in combinations(range(1, K+1), 3):
    S += 6 * gcd_list((a, b, c))
print(S)

from functools import reduce
from itertools import combinations

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

def gcd_list(A): return reduce(gcd, A)

K = int(input())
S = K * (K + 1) // 2
for a, b in combinations(range(1, K+1), 2):
    S += 6 * gcd(a, b)
for a, b, c in combinations(range(1, K+1), 3):
    S += 6 * gcd_list((a, b, c))
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 itertools import combinations
import fractions
n = int(input())
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += fractions.gcd(x[0],x[1])*6
        else:
            tmp = fractions.gcd(x[0],x[1])
            ans += fractions.gcd(x[2],tmp)*6

from itertools import combinations
import math
n = int(input()
ans = 0
for r in range(1,4): 
    
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        print(x)
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += math.gcd(x[0],x[1])*6
        else:
            tmp = math.gcd(x[0],x[1])
            ans += math.gcd(x[2],tmp)*6
print(ans)

from itertools import combinations
import math
n = int(input())
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += math.gcd(x[0],x[1])*6
        else:
            tmp = math.gcd(x[0],x[1])
            ans += math.gcd(x[2],tmp)*6

from itertools import combinations
import math
n = int(input()
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += math.gcd(x[0],x[1])*6
        else:
            tmp = math.gcd(x[0],x[1])
            ans += math.gcd(x[2],tmp)*6
print(ans)

from itertools import combinations
import math
n = int(input())
ans = 0
for r in range(1,4): 
    if r>n:
        break
    for x  in combinations([x+1 for x in range(n)],r):
        if len(x)==1:
            ans += x[0]
        elif len(x)==2:
            ans += math.gcd(x[0],x[1])*6
        else:
            tmp = math.gcd(x[0],x[1])
            ans += math.gcd(x[2],tmp)*6
print(ans)

Verdicts: Wrong Answer

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());
gcd = o;

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

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


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

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

print(gcd)


import math
 
K = int(input());
gcd = 0;
gcd1 = 0;
  
for a in range(1,K-1):
  for b in range(1,K-1):
    for c in range(1,K-1):
      gcd1 = math.gcd(a,b);
      gcd += math.gcd(gcd1,c);

print(gcd)

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

Wrong Answer

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
from functools import reduce

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
K = int(input())

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

print(count)

import numpy as np

K = int(input())
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)

print(np.sum(nums))

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

import math
from functools import reduce
from itertools import product
K=int(input())
gcd=0.
K=range(K)
for i,j,k in product(K,K,K):
            gcd+=reduce(math.gcd,(i+1,j+1,k+1))
print(gcd) 


import math
from functools import reduce
from itertools import product
K=int(input())
gcd=0.
for i in range(K):
    for j in range(K):
        a=math.gcd(i+1,j+1)
        for k in range(K):
            gcd+=math.gcd(a,k+1)
print(int(gcd)) 

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
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

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

print(ans)

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

K = readInt()
d = defaultdict(int)
ans=0
for a in range(1,K+1):
	for b in range(1,K+1):
		x = math.gcd(a,b)
		for c in range(1,K+1):
			ans+=math.gcd(x,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):
from math import gcd
K = int(input())
sumval = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            g = math.gcd(math.gcd(a,b),c)
            sumval += g
print(sumval)

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

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 euclid(m,n):
    
    if m < n:
        m, n = n, m
    while n != 0:
        m, n = n, m % n
    return m


num = int(input('')) 
ans_sum = 0

for a in range(1,num+1):
    for b in range(1,a):
        gcd_ab = euclid(a,num+1)
        for c in range(1,num+1):
            ans_sum = ans_sum + euclid(gcd_ab,c)

ans_sum = ans_sum * 2

print(ans_sum)




def euclid(m,n):
    
    if m < n:
        m, n = n, m
    while n != 0:
        m, n = n, m % n
    return m


num = int(input('')) 
ans_sum = 0

for a in range(1,num+1):
    for b in range(1,num+1):
        gcd_ab = euclid(a,num+1)
        for c in range(1,num+1):
            ans_sum = ans_sum + euclid(gcd_ab,c)

ans_sum = ans_sum

print(ans_sum)



def euclid(m,n):
    
    if m < n:
        m, n = n, m
    while n != 0:
        m, n = n, m % n
    return m


num = int(input('')) 
ans_sum = 0

for a in range(1,num+1):
    for b in range(1,a):
        gcd_ab = euclid(a,num+1)
        for c in range(1,num+1):
            ans_sum = ans_sum + euclid(gcd_ab,c)

ans_sum = ans_sum

print(ans_sum)




def euclid(m,n):
    
    if m < n:
        m, n = n, m
    while n != 0:
        m, n = n, m % n
    return m


num = int(input('')) 
ans_sum = 0

for a in range(1,num+1):
    for b in range(1,num+1):
        gcd_ab = euclid(a,b)
        for c in range(1,num+1):
            ans_sum = ans_sum + euclid(gcd_ab,c)

ans_sum = ans_sum

print(ans_sum)




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):
  if b > a:
    temp = b
    b = a
    a = temp
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)

def sum_of_gcd(k):
  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 and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans

n = int(input())
print(sum_of_gcd(n))

def gcd(a, b):
  if b > a:
    temp = b
    b = a
    a = temp
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)
def sum_of_gcd(k):
  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 and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j < k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans
 
n = int(input())
print(sum_of_gcd(n))

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):
mport math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, k + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
print(ans)

import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, k + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
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())
GCD = [[math.gcd(i, j)-1 for i in range(1, N+1)] for j in range(1, N+1)]
#print(GCD)
all_gcd = [GCD[GCD[i][j]][m] for i in range(N) for j in range(N) for m in range(N)]
print(sum(all_gcd))

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


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

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

for a in range(1, k+1):
    for b in range(1, a+1):
        for c in range(1, b+1):
            g_ab = fractions.gcd(a ,b)
            g_abc = fractions.gcd(g_ab, c)
            if a != b != c:
                ans += g_abc * 6
            elif a == b == c:
                ans += g_abc
            else:
                ans += g_abc * 3
print(ans)

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

for a in range(1, k+1):
    for b in range(1, a+1):
        for c in range(1, b+1):
            g_ab = math.gcd(a ,b)
            g_abc = math.gcd(g_ab, c)
            if a != b != c:
                ans += g_abc * 6
            elif a == b == c:
                ans += g_abc
            else:
                ans += g_abc * 3
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 nampy as np
k = int(input())

ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    tmp = np.gcd(a,b)
    for c in range(1,k+1):
      ans += np.gcd(tmp,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: 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(*number):
    return reduce(math.gcd, number)

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

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

print(sum)


import numpy as np

import math
from functools import reduce


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

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

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

print(sum)


import math
from functools import reduce


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

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

def main():
    sum = 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):
                sum += math.gcd(tmp, k)
    print(sum)

if __name__ == "__main__":
    main()


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):
k = int(input())
import fractions as f
a = [1]*3
total = 0
for i in range(1,k+1):
    total += f.gcd(a[0],a[1],a[i])
for i in range(1,k+1):
    total += f.gcd(a[0],a[i],a[2])
    if i == k:
        for j in range(1,k+1):
            total += f.gcd(a[0],a[i],a[j])
for i in range(1,k):
    total += f.gcd(a[i],a[1],a[2])
    if i == k:
        for j in range(1,k+1):
            total += f.gcd(a[i],a[1],a[j])
            if j == k:
                for l in range(1,k):
                    total += f.gcd(a[i],a[l],a[j])


print(total)



import collections

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

k=int(input())
cnt=collections.defaultdict(int)
for i in range(1,k+1): 
 for j in range(1,k+1):
   cnt[gcd(i,j)]+=1
ans=0
for i in range(1,k+1): 
 for key in cnt.keys():
   ans+=gcd(i,key)*cnt[key]
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)
n=200
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(i,j,k))
print(ans)

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

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):
import math
k=input()
a=1
b=1
c=1
s=0
for p in range(k):
  b=1
  for q in range(k):
    c=1
    for i in range(k):
      g=math.gcd(a,b)
      g=math.gcd(g,c)
      s=s+g
      c=c+1
    b=b+1
  a=a+1
print(s)

import math
k=200
s=0
for p in range(k):
  for q in range(k):
    g=math.gcd(p+1,q+1)
    for i in range(k):
      r=math.gcd(g,i+1)
      s=s+r
print(s)

import math
k=int(input())
s=0
for p in range(k):
  for q in range(k):
    g=math.gcd(p+1,q+1)
    for i in range(k):
      r=math.gcd(g,i+1)
      s=s+r
print(s)

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 colloctions import Counter
from scipy import gcd
 
def sum_of_gcd(N):
  temp = [gcd(i, k) for i in range(1, N+1) for k in range(1, N+1)]
  counts = Counter(temp)
  return sum([gcd(i, c)*counts[c] for i in range(1, N+1) for c in counts.keys()])
 
print(sum_of_gcd(int(input())))

from colloctions import Counter
import numpy as np

def sum_of_gcd(N):
  temp = [np.gcd(i, k) for i in range(1, N+1) for k in range(1, N+1)]
  counts = Counter(temp)
  return sum([np.gcd(i, c)*counts[c] for i in range(1, N+1) for c in counts.keys()])

print(sum_of_gcd(int(input())))

from scipy import gcd
from collections import Counter

def sum_of_gcd(N):
    temp = [gcd(i, k) for i in range(1, N+1) for k in range(1, N+1)]
    counts = Counter(temp)

    return sum([gcd(c, i)*counts[c] for i in range(1, N+1) for c in counts.keys()])

print(sum_of_gcd(int(input())))

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):
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:48:51 2020

@author: Aruto Hosaka
"""


import math

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

# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:48:51 2020

@author: Aruto Hosaka
"""


import math
import collections

K = int(input())
ans = 0
g = []
for a in range(K):
  for b in range(K):
      g.append(math.gcd(a+1, b+1))
G = collections.Counter(g)

for k in range(K):
  for c in range(K):
      ans += math.gcd(k+1, c+1)*G[k+1]
      
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=input()
K=int(K)
import fractions
def gcd(a,b,c):
  return fractions.gcd(fractions.gcd(a,b),c)
m=0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      m=m+gcd(i,j,k)
print(m)

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

from math import gcd
K = int(input())
m = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    w = gcd(i, j)
    if w==1:
      m += K
    else:
      for k in range(1, K+1):
        m += gcd(w, k)
print(m)

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):
%%time
import math
from functools import reduce

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

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

import math
from functools import reduce

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

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

from collections import defaultdict

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

gcd_cnt = defaultdict(int)
ans = 0
k = int(input())
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd_cnt[gcd(a, b)] += 1

for key in gcd_cnt:
    for c in range(1, k+1):
        ans += gcd(c, key) * gcd_cnt[key]
print(ans)

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):
import fractions
import itertools

k = int(input())

gcd_map = [[-1 for i in range(1,k+1)]for j in range(1,k+1)]

ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            if gcd_map[a-1][b-1]==-1:
                gab = fractions.gcd(a,b)
                gcd_map[a-1][b-1] = gab
                gcd_map[b-1][a-1] = gab
            
            else:
                gab = gcd_map[a-1][b-1]
            
            if gcd_map[gab-1][c-1]==-1:
                gbc = fractions.gcd(gab,c)
                gcd_map[gab-1][c-1] = gbc
                gcd_map[c-1][gab-1] = gbc

            else:
                gbc = gcd_map[gab-1][c-1]

            ans+=gbc
print(ans)
            


import math
k = int(input())

map_list = [[0 for i in range(k+1)]for j in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        map_list[i][j]=math.gcd(i,j)

ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        gcd1 = map_list[i][j]
        for k in range(1,k+1):
            ans+=map_list[k][gcd1]
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):
from math import gcd
from functools import reduce
def gcds(numbers):
  return reduce(gcd, numbers)
K = int(input())
ans = 0
for a in range(1, K + 1):
  for b in range(1, K + 1):
    for c in range(1, K + 1):
      ans += gcds(a, b, c)
print(ans)

from math import gcd
from functools import reduce
def gcds(*numbers):
  return reduce(gcd, numbers)
K = int(input())
ans1 = 0
ans2 = 0
ans3 = 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:
        ans1 += gcds(a, b, c)
      elif a == b or b == c or c == a:
        ans2 += gcds(a, b, c)
      else:
        ans3 += gcds(a, b, c)
print(ans1 + 3 * ans2 + 6 * ans3)

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
import itertools
k = int(input()) 
l = list(range(1, k + 1))
ans = 0
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
for v in itertools.product(l, repeat=3):
    ans += gcd(*list(v))
print(ans)

import math
n = int(input())
ans = 0
for i in range(1, n + 1):
  for j in range(1, n + 1):
    g = math.gcd(i, j)
    for k in range(1, n + 1):
      ans += math.gcd(g, 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):
import itertools
import fractions
from functools import reduce
k = int(input())
num = []
for i in range(1, k+1):
    num.append(i)
    num.append(i)
    num.append(i)
permutation_num = set(itertools.permutations(num, 3))
x = []
for j in permutation_num:
    y = reduce(fractions.gcd, j)
    x.append(y)

print(sum(x))

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

print(sum(x))

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

print(sum(x))

import math
k = int(input())
a = []
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):
            y = math.gcd(l, x)
            a.append(y)
print(sum(a))

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 math

K = int(input(K))

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

print(ans)


import math

K = int(input(K))

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

print(ans)

import math

K = int(input())

gcd_tmp = list()
total = 0
for b in range(1, K+1):
    for c in range(1, K+1):
        tmp = math.gcd(b, c)
        gcd_tmp.append(tmp)

gcd_tmp.sort()
length = len(gcd_tmp)

type_of_gcd = list()
num_of_gcd = list()

counter = 0
for i in range(length-1):
    counter += 1
    if gcd_tmp[i] != gcd_tmp[i+1]:
        type_of_gcd.append(gcd_tmp[i])
        num_of_gcd.append(counter)
        counter = 0
type_of_gcd.append(gcd_tmp[-1])
num_of_gcd.append(counter+1)

# print(gcd_tmp)
# print(type_of_gcd)
# print(num_of_gcd)


for a in range(1, K+1):
    for i in range(len(type_of_gcd)):
        tmp = math.gcd(a, type_of_gcd[i])
        total += tmp*num_of_gcd[i]

print(total)

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):
def solve(K: int):
    r = range(1, K+1)
    ans = 0
    d = {}

    for _ in it.product(r,r,r):	
        a, b, c = sorted(_)
        _a, _b, _c = a, b, c
        while c:
            if d.get((b, c), False):
                b = d[(b, c)]
                break 
            else:
                b, c = b, b%c,
        d[(_b, _c)] = b
        while b:
            if d.get((a, b), False):
                a = d[(a, b)]
                break 
            else:
                a, b = b, a%b
        d[(_a, _b)] = a
        ans += a
    print(ans)
    return


#!/usr/bin/env python3
import sys
import itertools as it
import numpy as np
from collections import Counter
d = {}
def _gcd(a,b):
    a, b = max(a,b), min(a,b)
    while b:
        if d.get((a, b), False):
            return d[(a, b)]
        else:
            a, b = b, a%b

    d[(a, b)] = a
    return a



#     if b == 0:
#         d[(a, b)] = a
#         return a


#     else:
#         ans = _gcd(b, a%b)
#         d[(a, b)] = ans
#         return ans

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

def solve(K: int):
    
    
    r = range(1, K+1)

    arr = []
    for (a,b) in it.product(r,r):
        arr.append(_gcd(a,b))
        # val_arr[a,b] += _gcd(a,b)
        # cnt_arr[a,b] += 1

    ans = 0
    cnt_dict = Counter(arr)
    for i in r:
        for key, cnt in cnt_dict.items():
            ans += _gcd(i,key)*cnt

    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    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 functools import reduce

k = int(input())

wa = 0

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

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

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

from math import gcd

k = int(input())

wa = 0

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


print(wa)


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

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

num = int(input())
ans = 0
for a in num:
    for b in num:
        for c in num:
            ans += math.gcd(a, b, c)
print(ans)

import math

num = int(input())
ans = 0
for a in range(num):
    for b in range(num):
        temp = math.gcd(a + 1, b + 1)
        for c in range(num):
            ans += math.gcd(temp, c + 1)
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 sys
import numpy as np
import math
# for AtCoder
import fractions
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())

sum = 0

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

for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            sum += gcd_list([i, j, k])
print(sum)


import sys
import numpy as np
import math
# for AtCoder
import fractions
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())

sum = 0

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

for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            sum += gcd_list([i, j, k])
print(sum)


import sys
import numpy as np
import math

from collections import deque 
from functools import reduce
from functools import lru_cache

@lru_cache(maxsize=None)
def gc(a, b):
    if (a % b == 0):
        return b
    return(gc(b, a%b))
# input = sys.stdin.readline

n = int(input())

sum = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        g = gc(i, j)
        for k in range(1, n+1):
            sum += gc(g, k)
print(sum)

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):
k = int(input())
s = 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):
            s += math.gcd(ab, c)
print(s)


import math

k = int(input())
s = 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):
            s += math.gcd(ab, c)
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):
K = int(input())

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

print(sum(Sum))

import math

K = int(input())

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

print(sum(Sum))


import math

K = int(input())

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

print(sum(Sum))

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

# input
K = int(input())

# process
gcdl = []
for i in range(K):
    l = []
    for j in range(K):
        l.append(math.gcd(i+1, j+1))
    gcdl.append(l)
print(gcdl)

ans = 0
for a in range(K):
    for b in range(a, K):
        for c in range(b, K):
            print([a, b, c])
            if a == c:
                ans += a+1
            elif b == c:
                ans += gcdl[a][b]*3
            elif a == b:
                ans += gcdl[a][c]*3
            else:
                t = gcdl[a][b]
                t = gcdl[t-1][c]
                ans += t*6

# output
print(ans)


import math

# input
K = int(input())

# process
gcdl = []
for i in range(K):
    l = []
    for j in range(K):
        l.append(math.gcd(i+1, j+1))
    gcdl.append(l)
# print(gcdl)

ans = 0
for a in range(K):
    for b in range(a, K):
        for c in range(b, K):
            # print([a, b, c])
            if a == c:
                ans += a+1
            elif b == c:
                ans += gcdl[a][b]*3
            elif a == b:
                ans += gcdl[a][c]*3
            else:
                t = gcdl[a][b]
                t = gcdl[t-1][c]
                ans += t*6

# output
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 sys, os, math
     
    def get_cd(n):
        cd = []
        for i in range(1, int(n/2)+1):
            if n % i == 0:
                cd.append(i)
            else:
                continue
        cd.append(n)
        return cd
     
    def get_gcd(a, b, c, cd_d):
        if 1 in [a, b, c]:
            return 1
        else:
            cd = sorted(list(set(cd_d[a]) & set(cd_d[b]) & set(cd_d[c])))
            return cd[-1]
     
    if __name__ == '__main__':
        k = int(input())
        cc_d = {}
        for i in range(1, k+1):
            cc_d[i] = get_cd(i)
     
        computed_d = {}
        s = 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:
                        s += a
                    else:
                        gcd = get_gcd(a, b, c, cc_d)
                        if a != b != c:
                            s += gcd*6
                        else:
                            s += gcd*3
        print(s)

import sys, os, math

def get_cd(n):
    cd = []
    for i in range(1, int(n/2)+1):
        if n % i == 0:
            cd.append(i)
        else:
            continue
    cd.append(n)
    return cd

def get_gcd(a, b, c, cd_d):
    if 1 in [a, b, c]:
        return 1
    else:
        cd = sorted(list(set(cd_d[a]) & set(cd_d[b]) & set(cd_d[c])))
        return cd[-1]

if __name__ == '__main__':
    k = int(input())
    cc_d = {}
    for i in range(1, k+1):
        cc_d[i] = get_cd(i)

    computed_d = {}
    s = 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:
                    s += a
                else:
                    gcd = get_gcd(a, b, c, cc_d)
                    if a != b != c:
                        s += gcd*6
                    else:
                        s += gcd*3
    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):
import sys

n = int(sys.argv[1])
total = 0

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

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

n = input()
total = 0

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

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

n = int(input())
total = 0

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

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))


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

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

K = int(input())
ans = 0

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

print(ans)


from math import gcd

K = int(input())
ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(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
from functools import reduce

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

def main():
    K = int(input())
    l = []
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
                g = gcd(i, j, i*j)
                l.append(g)

import math
from functools import reduce

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

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

import math
from functools import reduce

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

def main():
    K = int(input())
    l = []
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
                g = gcd(i, j, i*j)
                l.append(g)            
    print(sum(l))
main()

import math
from functools import reduce

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

def main():
    K = int(input())
    g = 0
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
            g += gcd(i, j, i*j)         
    print(g)
main()


from math import gcd
from functools import reduce


#     r = reduce(math.gcd, numbers)
#     return r

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

Verdicts: Wrong Answer

Runtime Error

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

if K==1:
  print(1)
  exit()
elif K==2:
  print(8)
  exit()
else:
  t=0
  for i in range(1,K-1):
    for j in range(i+1,K):
      for k in range(j+1,K+1):
        a=math.gcd(i,j)
        b=math.gcd(a,k)
        t+=b
  tw=0
  for i in range(1,K):
    for j in range(i+1,K+1):
      a=math.gcd(i,j)
      tw+=a
  
  on=0
  for i in range(1,K+1):
    on+=i
  print(t*6+tw*6+on)

K=int(input())
import math

if K==1:
  print(1)
  exit()
elif K==2:
  print(9)
  exit()
else:
  t=0
  for i in range(1,K-1):
    for j in range(i+1,K):
      for k in range(j+1,K+1):
        a=math.gcd(i,j)
        b=math.gcd(a,k)
        t+=b
  tw=0
  for i in range(1,K):
    for j in range(i+1,K+1):
      c=math.gcd(i,j)
      tw+=c
  
  on=0
  for i in range(1,K+1):
    on+=i
  print(t*6+tw*6+on)


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
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
tmp_sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      tmp_list = [i,j,k]
      tmp_sum += gcd_list(tmp_list)
print(tmp_sum)

K = int(input())
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
tmp_sum = 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:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)*6
      elif i == j and j == k:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)
      else:
        tmp_list = [i,j,k]
        tmp_sum += gcd_list(tmp_list)*3
print(tmp_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):
k=int(input())

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

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

print(res)

k=int(input())

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

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

print(res)

k=int(input())

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

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

print(res)

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):
import math
K = 200
ans = 0
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):
        ans += math.gcd(tmp,k)
print(ans)

import math
K = 200
ans = 0
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):
      if tmp==1:
        ans += 1
      else:
        ans += math.gcd(tmp,k)
print(ans)

import math
from functools import reduce
K = 200
ans = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += gcd(i,j,k)
print(ans)

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

Verdicts: Wrong Answer

Wrong Answer

Time Limit Exceeded

Accepted