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

K = int(input())
gcd_map = [[[0] * K for i in range(K)] for j in range(K)]

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][c-1] == 0:
					gcd = math.gcd(math.gcd(a,b), c)
					gcd_map[a-1][b-1][c-1] = gcd
					gcd_map[a-1][c-1][b-1] = gcd
					gcd_map[b-1][a-1][c-1] = gcd
					gcd_map[b-1][c-1][a-1] = gcd
					gcd_map[c-1][a-1][b-1] = gcd
					gcd_map[c-1][b-1][a-1] = gcd
					ans += gcd
				else:
					ans += gcd_map[a-1][b-1][c-1]

print(ans)

import math
 
K = int(input())
 
ans = 0
 
for a in range(1, K+1):
	for b in range(1, K+1):
		tmp = math.gcd(a,b)
		for c in range(1, K+1):
			ans += math.gcd(tmp,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

N = int(input())
sum = 0

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

print(sum)

import math

N = int(input())
sum = 0

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

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


dic = {}
ans = 0
n = int(input())
for i in range(n):
    for j in range(n):
        for k in range(n):
            key=(i+1)*(j+1)*(k+1)
            if key in dic:
                ans = ans+dic[key]
            else:
                val = gcd(gcd(i+1, j+1), k+1)
                dic[key] = val
                ans = ans + val
print(ans)

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

for p in range(1,k+1):
    for q in range(1,k+1):
        for r in range(1,k+1):
            ans=p
            ans = math.gcd(ans, q)
            ans = math.gcd(ans, r)
            sum_g+=ans
            ans=0
print(sum_g)


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

k=int(input())
import fractions

for p in range(1,k+1):
    for q in range(1,k+1):
        for r in range(1,k+1):
            ans=p
            ans = fractions.gcd(ans, q)
            ans = fractions.gcd(ans, r)
            sum_g+=ans
            ans=0
print(sum_g)


k=int(input())
import fractions
import itertools
sum_g=0
l=list(itertools.product([i for i in range(1,k+1)], repeat=3))
for p,q,r in l:
    ans=p
    ans = fractions.gcd(ans, q)
    ans = fractions.gcd(ans, r)
    sum_g+=ans
    ans=0
print(sum_g)


import math

K=int(input())
sum=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):
            b=math.gcd(a, k)
            sum = sum + b

print(sum)


Verdicts: Runtime Error

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 fractions
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):
      a=fractions.gcd(i,j)
      a=fractions.gcd(a,l)
      ans+=a
print(ans)

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

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


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

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

import math
k = int(input())
ans = 0
if k < 3:
    for i in range(1,k+1):
        for j in range(1,k+1):
            for n in range(1,k+1):
                ans += math.gcd(i,math.gcd(j,n))
else: 
    #i*j
    for n in range(1,k+1):
        for i in range(1,k+1):
            ans += math.gcd(n,i)
            for j in range(i+1,k+1):            
                ans += 2*(math.gcd(math.gcd(i,j),n))

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.  Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Submission attempts (in order):
import math

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



import math

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

from math import gcd

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.  Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Submission attempts (in order):
import math
from functools import reduce
K=int(input())
i=1
r=0
for i in range(K+1):
  j=1
  for j in range(K+1):
    k=1
    for k in range(K+1):
      if(i==1 or j==1 or k==1):
        r+=1
      elif(i==j and j==k):
        r+=i
      else:
        r+=math.gcd(i, math.gcd(j, k))
      k+=1
    j+=1
  i+=1
print(r)

import math

K=int(input())
r=0

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

mport math
from functools import reduce

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

K=int(input())

i=1
j=1
k=1
r=0
list=[2,3,5,7,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]

while(i<K+1):
  j=1
  f=0
  if(i in list == True):
    f=1
  while(j<K+1):
    k=1
    g=0
    if(j in list == True):
      g=1
    while(k<K+1):
      h=0
      if(k in list == True):
        h=1
      if(i==1 or j==1 or k==1):
        r+=1
      elif(f==1 and g==1 and h==1):
        if(i==j and j==k):
          r+=i
        else:
          r+=1
      else:
        r+=gcd(i, j, k)
      k+=1
    j+=1
  i+=1

print(r)


import math

K=int(input())
r=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):
      b=math.gcd(a,k)
      r+=b
print(r)

Verdicts: Wrong Answer

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):
from fractions import gcd
from functools import reduce
k = int(input())
def GCD(*numbers):
    return reduce(gcd, numbers)
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(i, j ,l)
print(ans)

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

Verdicts: Time Limit Exceeded

Accepted
Problem: Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.  Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Submission attempts (in order):
import math
def multi_gcd(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = fractions.gcd(ans, a[i])
    #print(ans)
    return ans
K = int(input())
sum_ = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            sum_ += multi_gcd([i, j, k])
print(sum_)

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

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
count=0
for p in range(1,k+1):
    for q in range(1,k+1):
        for r in range(1,k+1):
            count+=math.gcd(math.gcd(p,q), r)
            
print(count)

import math
k = int(input())
count=0
for p in range(1,k+1):
    for q in range(p,k+1):
        for r in range(q,k+1):
            if p == q == r:
                count+=math.gcd(math.gcd(p,q), r)
            elif p == q:
                count+=math.gcd(math.gcd(p,q), r)*3
            elif q == r:
                count+=math.gcd(math.gcd(p,q), r)*3
            elif p == r:
                count+=math.gcd(math.gcd(p,q), r)*3
            else:
                count+=math.gcd(math.gcd(p,q), r)*6
print(count)

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 fractions import gcd
import math
K = int(input())
Sum = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      x = math.gcd(i + 1, j + 1)
      y = math.gcd(i + 1, k + 1)
      Sum = Sum + math.gcd(x, y)
print(Sum)

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

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()) + 1
d = 0

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

from math import gcd

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

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

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=200
ans=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            tempgcd=math.gcd(a,b)
            ans=ans+math.gcd(tempgcd,c)
print(ans)

import math
K=200
ans=0
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            tempgcd=math.gcd(a,b)
            if a==b or b==c or a==c:
              if a==b and b==c:
                ans=ans+math.gcd(tempgcd,c)
              else:
                ans=ans+3*math.gcd(tempgcd,c)
            else:
              ans=ans+6*math.gcd(tempgcd,c)
            
print(ans)

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


Verdicts: Time Limit Exceeded

Wrong Answer

Accepted
Problem: Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.  Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Submission attempts (in order):
import sys
from fractions import gcd
input = sys.stdin.readline

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)


import sys
from math import gcd
input = sys.stdin.readline

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

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

from math import gcd
k = int(input())
sum = 0
lst = []
for a in range(1,k+1):
  for b in range(1,k+1):
      g = gcd(a,b)
      lst.append(g)
for c in range(1,k+1):
    for i in range(len(lst)):
        sum += gcd(lst[i],c)     
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):
import math

K = int(input())
ans = 0

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

print(ans)

import math

K = int(input())
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 fractinons
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+=fractions.gcd(fractions.gcd(a,b),c)
print(ans)

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



Verdicts: Runtime Error

Accepted
Problem: Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.  Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Submission attempts (in order):
from math import gcd

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

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

from math import gcd

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

for i in range(1,K):
  for j in range(1,K):
    for k in range(1,K):
       sum+=gcd(gcd(i,j),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):
k = int(input())

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

total = 0
for i in range(1, k+1):
  for j in range(i, k+1):
    for k in range(j, k+1):
      if i == j and j == k and i == k:
        x = 1
      elif i != j and i != k and j != k:
        x = 6
      else:
        x = 3
        
      total += x * gcd_list([i, j, k])
print(total)

from itertools import combinations
import math
from functools import reduce

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

n = int(input())

total = 0
for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if  i == j and j == k and i == k:
                x = 1
            elif i != j and j != k and i != k:
                x = 6
            else:
                x = 3
            
            total += x * gcd_list([i, j, k])
        
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
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

k = int(read())
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        n = math.gcd(a, b)
        for c in range(1, k + 1):
            ans += math.gcd(n, 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

K = int(input())

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

print(sum)


import math

K = int(input())

sum = 0
for a in range(1, K+1) :
    for b in range(1 , K+1) :
        tmp = math.gcd(a, b)
        for c in range(1 , K+1) :
            sum = sum + math.gcd(tmp, 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):
from math import gcd
k = int(input())
sum = 0
for a in range(1, k):
  for b in range(1, k):
    tmp = gcd(a,b)
    for c in range(1, k):
      sum += gcd(tmp, c)
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):
    tmp = gcd(a,b)
    for c in range(1, k+1):
      sum += gcd(tmp, 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):
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)


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):
def main():
    k = int(input())
    r = 0
    for ia in range(1, k + 1):
        for ib in range(1, k + 1):
            for ic in range(1, k + 1):
                t1 = gcd(ib, ic)
                r += gcd(t1,ia)
    print(r)

if __name__ == '__main__':
    main()

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

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

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

if __name__ == '__main__':
    main()


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    k = int(input())

    k2 = np.arange(1, k+1)
    k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2))
    print(k2gcd.sum())

if __name__ == '__main__':
    main()

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 sys
import os
import fractions
import itertools

def file_input():
    f = open('Beginner_Contest_162/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    K=int(input())
    # map(int, input().split())
    sum=0

    combi_l = itertools.combinations_with_replacement(range(1,K+1),3)
    # print(combi_l)

    for combi in combi_l:
        # print(combi)
        if combi[0]==combi[1]==combi[2]:
            sum+=fractions.gcd(fractions.gcd(combi[0],combi[1]),combi[2])
        elif combi[0]==combi[1] or combi[1]==combi[2] or combi[2]==combi[0]:
            sum+=3*fractions.gcd(fractions.gcd(combi[0],combi[1]),combi[2])
        else:
            sum+=6*fractions.gcd(fractions.gcd(combi[0],combi[1]),combi[2])

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

    print(sum)

if __name__ == '__main__':
    main()


import sys
import os
import fractions

def file_input():
    f = open('Beginner_Contest_162/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    K=int(input())
    # map(int, input().split())
    sum=0

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

    print(sum)

if __name__ == '__main__':
    main()


import sys
import os
import itertools

def file_input():
    f = open('Beginner_Contest_162/input.txt', 'r')
    sys.stdin = f

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

def main():
    #file_input()
    K=int(input())
    # map(int, input().split())
    sum=0

    combi_l = itertools.combinations_with_replacement(range(1,K+1),3)
    # print(combi_l)

    for combi in combi_l:
        # print(combi)
        if combi[0]==combi[1]==combi[2]:
            sum+=gcd(gcd(combi[0],combi[1]),combi[2])
        elif combi[0]==combi[1] or combi[1]==combi[2] or combi[2]==combi[0]:
            sum+=3*gcd(gcd(combi[0],combi[1]),combi[2])
        else:
            sum+=6*gcd(gcd(combi[0],combi[1]),combi[2])

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

    print(sum)

if __name__ == '__main__':
    main()


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())
total = 0

for a in range(1, k + 1):
    for b in range(1, k + 1):
        if gcd(a, b) == 1:
            total += 1 * k
            continue
        else:
            for c in range(1, k + 1):
                total += gcd(a, b, c)
print(total)

import math
from functools import reduce

k = int(input())
total = 0

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

for a in range(1, k + 1):
    for b in range(1, k + 1):
        if gcd(a, b) == 1:
            total += 1 * k
            continue
        else:
            for c in range(1, k + 1):
                total += gcd(a, b, c)
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
N = int(input())
ans = (1+N)*N/2
for i in range(1,N+1):
  for j in range(1,i):
    ans += math.gcd(i,j)*3
for i in range(!,N+1):
  for j in range(1,i):
    if i== j:
      break
    for k in range(1,j):
      if i == k or j == k:
        break
      else:
        ans += math.gcd(i,j,k)*6
print(ans)

import math
N = int(input())
ans = (1+N)*N/2
for i in range(1,N+1):
  for j in range(1,i):
    ans += math.gcd(i,j)*6
for i in range(1,N+1):
  for j in range(1,i):
    if i== j:
      break
    for k in range(1,j):
      if i == k or j == k:
        break
      else:
        ans += math.gcd(k,math.gcd(i,j))*6
print(int(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

ans = 0
ans += 0.5*k*(k+1)
# print(ans)

for a in range(1, k):
    for b in range(a+1,k+1):
        n = math.gcd(a, b)
        ans += n*6
        # print(a, b, n)

for i in range(1, k-1):
    for j in range(i+1, k):
        for k in range(j+1, k+1):
            d = math.gcd(i, j)
            ans += math.gcd(d, k)*6
            # print(i, j, k)

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

print(int(ans))

k = int(input())

import math

ans = 0
ans += 0.5*k*(k+1)
# print(ans)

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


#     for j in range(i+1, k):
#         for k in range(j+1, k+1):
#             d = math.gcd(i, j)
#             ans += math.gcd(d, k)*6

print(int(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, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
c = 0
K = INT()
ans = 0
 
for i in range(1, K + 1):
    for j in range(1, K + 1):
        a = gcd(i, j)
        for k in range(1, K + 1):
            b = gcd(a, k)
            ans += b
print(ans)            
 

import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
# from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
c = 0
K = INT()
ans = 0
 
for i in range(1, K + 1):
    for j in range(1, K + 1):
        a = gcd(i, j)
        for k in range(1, K + 1):
            b = gcd(a, k)
            ans += b
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(k+1):
  for b in range(k+1):
    for c in range(k+1):
      ans += gcd(gcd(a,b),c)

print(ans)

from math import gcd

k = int(input())
ans = 0

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

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.  Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

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



import functools
from fractions import gcd
n = int(input())
@functools.lru_cache(None)
def main(n):
  g=0
  for i in range (1, n+1):
    for j in range (1, n+1):
      for k in range (1, n+1):
        g  += gcd(gcd(i,j),k)
  return (g)
print(main(n))

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

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

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

import functools
from math import gcd
n = int(input())
@functools.lru_cache(None)
def main(n):
  g=0
  for i in range (1, n+1):
    for j in range (1, n+1):
      for k in range (1, n+1):
        g  += gcd(gcd(i,j),k)
  return (g)
print(main(n))

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):
k=int(input())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k and k!=i:
        x+=6*c
      elif (i!=j and j==k) or (j!=k and k==i) or (k!=i and i==j):
        x+=3*c
      else:
        x+=c
print(x)

k=int(input())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif i==j==k:
        x+=c
      else:
        x+=3*c
print(x)

k=int(input())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif (i!=j and j==k) or (k!=i and i==j):
        x+=3*c
      else:
        x+=c
print(x)

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

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):
from math import gcd
k=int(input())
cnt=0
for i in range(k):
  for p in range(k):
    for q in range(k):
      cnt+=gcd(i,p,q)
      
print(cnt)
  

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

      
print(cnt)
  



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 fractions import gcd

k = int(input())

result = 0

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

print(result)

import fractions
from functools import reduce

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

k = int(input())

result = 0

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

print(result)

import math
import itertools

k = int(input())
result = 0

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

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

print(result)

Verdicts: Wrong Answer

Time Limit Exceeded

Accepted
Problem: Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.  Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

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

gcache = { }
s = 0

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

print(s)


k = int(input())

from math import gcd

s = 0
for a in range(1, k+1):
  for b in range(1, k+1):
    g = gcd(a, b)
    for c in range(1, k+1):
      s += gcd(g, 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 fractions import gcd
 
k=int(input())
 
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1, k+1):
      ans+=gcd(gcd(i,j),l)
 
print(ans)

from math import gcd

k=int(input())

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

print(ans)

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 fractions

K = int(input())

ans = 0
a=[]
for i in range(1,K+1):
	for j in range(1, K+1):
		tmp = fractions.gcd(i,j)
		for k in range(1, K+1):
			ans+=fractions.gcd(tmp,k)

print(ans)

import math
K = int(input())

ans = 0
a=[]
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: 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):
# coding: utf-8
import math
from functools import reduce

K = int(input())
tmp = []

c = 0
for i in range(K):
    for j in range(K):
        tmp.append(math.gcd(i + 1, j + 1))
        c = c + 1

tmp2 = []
for k in tmp:
    for m in range(K):
        tmp2.append(math.gcd(k, m+1))

print("sum:",sum(tmp2))

# coding: utf-8
import math
from functools import reduce

K = int(input())
tmp = []

c = 0
for i in range(K):
    for j in range(K):
        tmp.append(math.gcd(i + 1, j + 1))
        c = c + 1

tmp2 = []
for k in tmp:
    for m in range(K):
        tmp2.append(math.gcd(k, m+1))

print(sum(tmp2))

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
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

K = int(read())

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


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

K = int(read())

x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print(nums.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):
from math import gcd
k=200
ans=0
for i in range(1,k+1):
    for j in range(i,k+1):
        for k in range(j,k+1):
            s=len(set([i,j,k]))
            if s==1:
                p=1
            elif s==2:
                p=3
            elif s==3:
                p=6
            tmp=gcd(i,j)
            tmp= p*gcd(tmp,k)
            ans+=tmp
print(ans)

from math import gcd
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):
            s=len(set([i,j,k]))
            if s==1:
                p=1
            elif s==2:
                p=3
            elif s==3:
                p=6
            tmp=gcd(i,j)
            tmp= p*gcd(tmp,k)
            ans+=tmp
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):
n = int(input())
ans = 0

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

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

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

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

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(imput())
n = 0

for i in range(1,k+1)
    for j in range(1,k+1)
        a=math.gcd(i,j)
        for l in range(1,k+1)
            b=math.gcd(a,l)
            n += b

print(n)

import math

k = int(input())
n = 0

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

print(n)

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())
l=list(range(1, k+1))
import itertools
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd, numbers)
ans=0
for v in itertools.combinations_with_replacement(l, 3):
  ans+=gcd(*v)
print(ans)

k=int(input())
l=list(range(1, k+1))
import itertools
import math
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd, numbers)
ans=0
for v in itertools.combinations_with_replacement(l, 3):
  if v[0]==v[1]==v[2]:
    ans+=gcd(*v)
  elif v[0]==v[1]:
    ans+=gcd(*v)*3
  elif v[1]==v[2]:
    ans+=gcd(*v)*3
  elif v[0]==v[2]:
    ans+=gcd(*v)*3
  else:
    ans+=gcd(*v)*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 math
#import itertools
num = (int)(input())
total = 0


#print(total)
for i in range(2, num + 1):
  for j in range(2, num + 1):
    for k in range(2, num + 1):
      total += math.gcd(math.gcd(i, j), k)
print(total)

import math
num = (int)(input())
total = 0

for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = math.gcd(i, j)
    for k in range(1, num + 1):
      total += math.gcd(sub, k)
print(total)

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 itertools as it
import fractions

K = int(input())

gcd_list = []
for i, j, k in it.product(range(1, K+1), range(1, K+1), range(1, K+1)):
    gcd_ = fractions.gcd(fractions.gcd(i, j), k)
    gcd_list.append(gcd_)
print(sum(gcd_list))


import itertools as it
import math

K = int(input())

itr = range(1, K+1)
gcd_ = sum([math.gcd(math.gcd(i, j), k)
            for i, j, k in it.product(itr, itr, itr)])
print(gcd_)


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 fractions
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        ab = fractions.gcd(i,j)
        if ab == 0:
            continue
        for k in range(1,K+1):
            ans += fractions.gcd(ab,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):
        ab = gcd(i,j)
        if ab == 0:
            continue
        for k in range(1,K+1):
            ans += gcd(ab,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 math
from functools import reduce


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

n=int(input())
l1=range(1,n+1)
l2=range(1,n+1)
l3=range(1,n+1)

count=0

for i in l1:
    for j in l2:
        te=gcd(i,j)
        for k in l3:
            count+=(te,k)

print(count)

import math
from functools import reduce


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

n=int(input())
l1=range(1,n+1)
l2=range(1,n+1)
l3=range(1,n+1)

count=0

for i in l1:
    for j in l2:
        te=math.gcd(i,j)
        for k in l3:
            count+=math.gcd(te,k)

print(count)

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

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

from math import gcd
 
K = int(input())
 
result = 0
for a in range(1, K + 1):
  for b in range(1, K + 1):
    for c in range(1, K + 1):
      result += gcd(c, gcd(a, b))
      
print(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):
n = int(input())
ans = 0
for i in range(1,n + 1):
    for j in range(1, n + 1):
        f = fractions.gcd(i, j)
        for k in range(1, n + 1):
            ans += fractions.gcd(f, k)
print(ans)

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

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

Verdicts: 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):
N = int(input())
N = N+1
sum = 0

import math

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

for i in range(1, N):
    for j in range(1, N):
        for k in range(1, N):
            sum += (gcd(gcd(i, j), k)

print( sum )


N = int(input())
N = N+1
sum = 0

import math

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

for i in range(1, N):
    for j in range(1, N):
        for k in range(1, N):
            sum += gcd(gcd(i, j), k)

print( sum )


from math import gcd as 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(j, k), 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
K = int(input())

ans = 0

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

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

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

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

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

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

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted