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):
n=int(input())
# a,b,c=map(int,input().split())
cnt=0
def gcd(a,b):
    if a==0: return b
    else: return gcd(b%a,a)
# print(gcd(a,b))

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

for i in range(1,n+1):
    for j in range ( 1 , n + 1 ):
        for k in range ( 1 , n + 1 ):
            # cnt+=gcd_3(i,j,k)
            cnt+=1


print(cnt)

def main():
    from math import gcd

    K = int(input())

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

def main():
    from math import gcd

    K = int(input())

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


main()

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

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

Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
[N, K] = [int(i) for i in input().split()]
print(min(N%K, -N%K))

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):
            s = math.gcd(a, b)
            t = math.gcd(s, c)
            if a == c:
                ans += t
            elif (a == b or b == c) and a != c:
                ans += 3*t
            else:
                ans += 6*t
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)
  
K = int(input())
count = 0
for i in range(1,K+1):
  for j in range(i+1,K+1):
    for k in range(j+1,K+1):
      count += 6*(gcd(i,j,k))
      
for i in range(1,K+1):
  for j in range(i+1,K+1):
    count += 3*(gcd(i,j))

for i in range(1,K+1):
  count += i
      
print(count)

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
K = int(input())
count = 0
for i in range(1,K-1):
  for j in range(i+1,K):
    for k in range(j+1,K+1):
      count += 6*(gcd(i,j,k))
      
for i in range(1,K):
  for j in range(i+1,K+1):
    count += 6*(gcd(i,j))

for i in range(1,K+1):
  count += i
      
print(count)

Verdicts: Wrong Answer

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

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



# coding: utf-8
# Your code here!

def MI():return map(int,input().split())
def LI():return list(MI())

n=int(input())

import math
from collections import Counter


    # return reduce(math.gcd, numbers)

ans=0
t=[]
for i in range(1,n+1):
    for j in range(1,n+1):
        t.append(math.gcd(i,j))
        
c=Counter(t).items()

for (i,j) in c:
    for k in range(1,n+1):
        ans+=math.gcd(i,k)*j
        # p\rint(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 fractions import gcd

K = int(input())

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


from fractions import gcd

K = int(input())

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

from fractions import gcd

K = int(input())

res = 0
tmp = 0
d = []
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:
                res += i
            elif i == j:
                res += gcd(i,k)
            elif i == k:
                res += gcd(j,k)
            elif j == k:
                res += gcd(i,j)
            else:
                res += gcd(gcd(i,j),k)
print(res)

from math import gcd

K = int(input())

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

Verdicts: Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

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

Submission attempts (in order):
import math 
from itertools import product
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd,numbers)
K=int(input())
A=[]
as=range(1,K+1)
bs=range(1,K+1)
cs=range(1,K+1)
for a,b,c in product(as,bs,cs):
  s=gcd(a,b,c)
  A.append(s)
print(sum(A))
  
    
      A.append(s)
print(sum(A))

import math 
from functools import reduce
def gcd(*numbers):
  return reduce(math.gcd,numbers)
K=int(input())
A=[]
for i in range(K):
  for j in range(K):
    for k in range(K):
      s=gcd(i,j,k)
      A.append(s)
print(sum(A))

import math 
K=int(input())
A=[]
for i in range(K):
  for j in range(K):
    for k in range(K):
      s=gcd(i,j,k)
      A.append(s)
print(sum(A)


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

Verdicts: 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())
sum = 0

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

import math
 
k = int(input())
sum = 0
 
for a in range(k - 2):
  for b in range(a + 1, k - 1):
    for c in range(b + 1, k):
      sum += 6 * math.gcd(a + 1, math.gcd(b + 1, c + 1))
      
for a in range(k - 1):
  for b in range(a + 1, k):
    sum += 3 * math.gcd(a + 1, b + 1)
    
sum += k * (k + 1) // 2
      
print(sum)

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

K = int(sys.stdin.readline())
ans = 0

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

print(ans)

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

#i<j<k
for i in range(1, K-1):
    for j in range(i+1, K):
        for k in range(j+1, K+1):
            gcd_ij_1 = math.gcd(i, j)
            gcd_ijk_1 = math.gcd(gcd_ij_1, k)
            ans += gcd_ijk_1 * 6

for l in range(1, K):
    for m in range(l+1, K+1):
        gcd_lm_1 = math.gcd(l,m)
        ans += gcd_lm_1 * 6

for n in range(1, K+1):
    ans += n

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 fractions import gcd
N = int(input())

ll = [i for i in range(1,N+1)]   
ans = 0

def aaa(a):
    d = gcd(a[0],a[1])
    return gcd(d,a[2])

lll = []
for i in ll:
    for j in ll:
        for k in ll:
            lll.append((i ,j, k))

for ii in lll:
    ans += aaa(ii)
print(ans)

from fractions import gcd
N = int(input())

ll = [i for i in range(1,N+1)]   
ans = 0

def aaa(a):
    d = gcd(a[0],a[1])
    return gcd(d,a[2])

lll = []
for i in ll:
    for j in ll:
        for k in ll:
            lll.append((i ,j, k))

for ii in lll:
    ans += aaa(ii)
print(ans)

from fractions import gcd
N = int(input())

ll = [i for i in range(1,N+1)]   
ans = 0

for i in ll:
    for j in ll:
        s = gcd(i,j)
        for k in ll:
            ans += gcd(s,k)
print(ans)

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

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):
import fractions
x=0
K=int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    for h in range(1,K+1):
      if i==j and j==h:
        x=x+i
      elif i==j or j==h:
        x=x+fractions.gcd(i,h)
      else:
        x=x+fractions.gcd(i,fractions.gcd(j,h))
print(x)

import math
x=0;y=0
K=int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    y=math.gcd(i,j)
    for h in range(1,K+1):
      x=x+math.gcd(y,h)
print(x)

Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
def main():
    n = input()
    print('Yes') if '7' in n else print('No')

if __name__ == "__main__":
    main()

import math
 
def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            tmp = math.gcd(i,j)
            for k in range(1,n+1):
                ans += math.gcd(tmp,k)
 
    print(ans)
 
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 math import gcd
k = int(input())
ans = 0
for a in range(1,k+1):
  for b in range(a,k+1):
    ab = gcd(a,b)
    for c in range(c,k+1):
      g = gcd(ab,c)
      if a == b == c:
        ans += g
      elif a!=b!=c!=a:
        ans += g*6
      else:
        ans += g*3
print(ans)


import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

k = ni()
ans = 0

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

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

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

print(ans)


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

for a in range(k):
    for b in range(k):
        d = math.gcd(a + 1, b + 1)
        for c in range(k):
            ans += math.gcd(d, 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):
#C - Sum of gcd of Tuples (Easy)
K = int(input())
sum = 0

import fractions
def N_gcd(ans):
    ans2 = ans[0]
    for n in range(1, 3):
        ans2 = fractions.gcd(ans2, ans[n])
    return ans2

for i in range(1,K+1):
    for j in range(1,K+1):
            for k in range(1,K+1):
                a = [i,j,k]
                sum += N_gcd(a)


print(sum)

#C - Sum of gcd of Tuples (Easy)
K = int(input())
DP =[]
ans = 0
import math
# from functools import reduce

#     return reduce(math.gcd, numbers)



#     return reduce(math.gcd, numbers)

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)
            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):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
result = 0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            result+=gcd(i,j,k)
print(result)

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
result = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            result+=gcd(i,j,k)
result

import itertools
import math
from functools import reduce
def gcd(numbers):
    return reduce(math.gcd, numbers)
N = int(input())
l = [i for i in range(1,N+1)]
h = itertools.combinations_with_replacement(l, 3)

result=0
for v in h:
    ans=gcd(v)
    i,j,k=zip(v)
    if (i==j)&(i==k):
        result += ans
    elif ((i==j)&(i!=k))|((i==k)&(i!=j))|((j==k)&(j!=i)):
        result += (ans*3)
    else:
        result += (ans*6)
    
print(result)

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

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)

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

def gcd(p,q):
  if p % q == 0:
    return q
  return gcd(q, p%q)

from math import gcd

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



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

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

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

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

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
def gcd(a, b, c):
  import fractions
  lis = [a, b, c]
  gc = lis[0]
  for i in range(0, 3):
      gc = fractions.gcd(gc, lis[i])
  return gc
def main():
  K = int(input())
  ans = 0
  for p in range(1, K+1):
    for s in range(p, K+1):
      for k in range(s, K+1):
        if p == s == k:
          ans += p
        elif p == s or s == k or p == k:
          ans += 3 * gcd(p, s, k)
        else:
          ans += 6 * gcd(p, s, k)
  print(ans)

if __name__=='__main__':
    main()

def gcd(a, b, c):
  x = gcd2(a, b)
  y = gcd2(b, c)
  return gcd2(x, y)

def gcd2(x, y):
    if y == 0:
        return x
    else:
        return gcd2(y,x%y)

def main():
  K = int(input())
  ans = 0
  for p in range(1, K+1):
    for s in range(p, K+1):
      for k in range(s, K+1):
        if p == s == k:
          ans += p
        elif p == s or s == k or p == k:
          ans += 3 * gcd(p, s, k)
        else:
          ans += 6 * gcd(p, s, k)
  print(ans)

if __name__=='__main__':
    main()

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
import numpy as np

K = int(input())

gcdSum = 0

myArr = np.zeros((K, K), dtype=int)

for iIndx in range(K):
    for jIndx in range(K):
        myArr[iIndx, jIndx] = math.gcd(iIndx, jIndx)

for iIndx in range(K):
    for jIndx in range(K):
        presGcd = myArr[iIndx, jIndx]
        for kIndx in range(K):
            gcdSum += myArr[presGcd, kIndx]

print(gcdSum)

import math

K = int(input())

gcdSum = 0
myDict = {}

for iIndx in range(1, K+1):
    for jIndx in range(1, iIndx+1):
        presGcd = math.gcd(iIndx, jIndx)
        if (presGcd in list(myDict.keys())) and (iIndx == jIndx):
            myDict[presGcd] += 1
        elif (presGcd in list(myDict.keys())) and (iIndx != jIndx):
            myDict[presGcd] += 2
        elif (presGcd not in list(myDict.keys())) and (iIndx == jIndx):
            myDict[presGcd] = 1
        elif (presGcd not in list(myDict.keys())) and (iIndx != jIndx):
            myDict[presGcd] = 2
        else:
            print('error')

for kIndx in range(1, K+1):
    for keyItem in list(myDict.keys()):
        gcdSum += math.gcd(keyItem, kIndx) * myDict[keyItem]

print(gcdSum)

Verdicts: Wrong Answer

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

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

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

k = int(input())
tmp = 0
for a range(1, k+1):
  for b range(1, k+1):
    for c range(1, k+1):
      tmp += gcd_list([a, b, c])
print(tmp)

import math
from functools import reduce

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

k = int(input())
tmp = 0
for a in range(1, k+1):
  for b in range(a, k+1):
    for c in range(b, k+1):
      #print('a='+str(a)+', b='+str(b)+', c='+str(c))
      if a == b and a == c:
        tmp += gcd_list([a, b, c]) 
      elif a == b and a != c:
        tmp += gcd_list([a, b, c]) * 3
#        tmp += gcd_list([b, c, a]) 
#        tmp += gcd_list([c, a, b]) 
      elif b == c and a != c:
        tmp += gcd_list([a, b, c]) * 3
#        tmp += gcd_list([b, c, a]) 
#        tmp += gcd_list([c, a, b]) 
      elif a == c and b != c:
        tmp += gcd_list([a, b, c]) * 3
#        tmp += gcd_list([b, c, a]) 
#        tmp += gcd_list([c, a, b]) 
      else:
        tmp += gcd_list([a, b, c]) * 6
#        tmp += gcd_list([a, c, b])
#        tmp += gcd_list([b, a, c])
#        tmp += gcd_list([b, c, a])
#        tmp += gcd_list([c, a, b])
#        tmp += gcd_list([c, b, a])
print(tmp)


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 math

K = int(input())
cnt = 0

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

from math import gcd

K = int(input())
cnt = 0

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

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

print(total)


import math
import numpy
K = int(input())

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

print(total)


Verdicts: 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())+1
for i in range(1, k):
    for j in range(1, k):
        temp = math.gcd(i, j)
        for x in range(1, k):
            sum += math.gcd(temp, x)


print(sum)

import math
for i in range(1, k):
    for j in range(1, k):
        temp = math.gcd(i, j)
        for x in range(1,k):
            sum += math.gcd(temp,x)


print(sum)

import math
import time
start = time.time()
sum = 0
k= 200
for i in range(k):
    for j in range(k):
        for x in range(k):
            sum += math.gcd(x+1, math.gcd(i+1, j+1))

print(sum)

#print(time.time()-start)

import math

k = int(input())+1

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


print(sum)

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

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

Verdicts: Runtime Error

Runtime Error

Time Limit Exceeded

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
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

count = 0
from itertools import product
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            count += gcd(a, b, c)

print(count)

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

k = int(input())

count = 0
from itertools import product
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            abc = len(set([a,b,c]))
            t = gcd(a, b, c)
            count += t if abc == 1 else t * 3 if abc == 2 else t * 6

print(count)

Verdicts: Wrong Answer

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

Submission attempts (in order):
import numpy

L = int(input())
print(numpy.sum([math.gcd(math.gcd(i + 1, j + 1), k + 1) for i in range(L) for j in range(L) for k in range(L)]))

import numpy
import math

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

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

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

print(sum)


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

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

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

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

k=int(input())
tot=0
for l,m,n in itertools.product(range(1,k+1),range(1,k+1),range(1,k+1)):
    ans=fractions.gcd(m,l%m)
    ans=fractions.gcd(ans,n)
    tot+=ans
print(tot)

import fractions

k=int(input())
tot=0

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

import math
import fractions

k=int(input())
tot=0

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

import fractions
import itertools

k=int(input())
tot=0
for l,m,n in itertools.product(range(1,k+1),range(1,k+1),range(1,k+1)):
    ans=l
    ans=fractions.gcd(ans,m)
    ans=fractions.gcd(ans,n)
    tot+=ans
print(tot)

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


Verdicts: 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):
import math
from functools import reduce
k = int(input())
l = [a,b,c]
gcd = []
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
for l[0] in range(1,k+1):
    for l[1] in range(1,k+1):
        for l[2] in range(1,k+1):
            gcd.append(gcd_list(l))
print(sum(gcd))

import math
ans = 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):
            ans += math.gcd(tmp,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):
form math import gcd
num = (int)(input())
total = 0
 
for i in range(1, num + 1):
  for j in range(1, num + 1):
    sub = gcd(i, j)
    for k in range(1, num + 1):
      total += gcd(sub, k)
print(total)

from math import gcd
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)

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

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

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

k = int(input())
ans = 0

num = list(itertools.combinations_with_replacement(range(1,k+1),3))
print(num)
for l in num:
    a,b,c = l
    if a==b==c:
        ans += a
    elif a!=b!=c:
        ans += gcd_3(a,b,c)*6
    else:
        ans += gcd_3(a,b,c)*3
print(ans)

import itertools

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

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

k = int(input())
ans = 0

num = list(itertools.combinations_with_replacement(range(1,k+1),3))

for l in num:
    a,b,c = l
    if a==b==c:
        ans += a
    elif a!=b!=c:
        ans += gcd_3(a,b,c)*6
    else:
        ans += gcd_3(a,b,c)*3
print(ans)

Verdicts: Wrong Answer

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

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

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

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

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

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

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import math
import numpy as np
import itertools

for l, m, n in itertools.product(range(k), range(k), range(k))

k = int(input())
tot = 0


g = np.array([[-1] * (k + 1)] * (k + 1), dtype=np.int64)

for l in range(1, k + 1):
    for m in range(1, k + 1):
        for n in range(1, k + 1):
            if g[l][m] == -1:
                g[l][m] = math.gcd(l, m)
            lm_gcd = g[l][m]
            
            if g[lm_gcd][n] == -1:
                g[lm_gcd][n] = math.gcd(lm_gcd, n)
            
            tot += g[lm_gcd][n]
print(tot) 

import math
import numpy as np
import itertools


k = int(input())
tot = 0


g = np.array([[-1] * (k + 1)] * (k + 1), dtype=np.int64)

for l, m, n in itertools.product(range(k + 1), range(k + 1), range(k + 1)):
    if g[l][m] == -1:
        g[l][m] = math.gcd(l, m)
    lm_gcd = g[l][m]

    if g[lm_gcd][n] == -1:
        g[lm_gcd][n] = math.gcd(lm_gcd, n)
    tot += g[lm_gcd][n]
    
print(tot) 

from math import gcd

k = int(input())
tot = 0

for l in range(1, k + 1):
    for m in range(1, k + 1):
        for n in range(1, k + 1):
            tot += gcd(gcd(l, m), n)
print(tot) 

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 math

gcd_sum = 0

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

print(gcd_sum)

K = int(input())

import math
 
gcd_sum = 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):
            gcd_sum += math.gcd(ab,c)       
 
print(gcd_sum)

Verdicts: Wrong Answer

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

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k+1):
        for j in range(1, k+1):
            sum += gcd(i, j)*3

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k+1):
        for j in range(i+1, k+1):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k+1):
        for j in range(1, k+1):
            sum += gcd(i, j)*3

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k-1):
        for j in range(i+1, k):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k):
        for j in range(i+1, k+1):
            sum += gcd(i, j)*6

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k-1):
        for j in range(i+1, k):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

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

def main():
    n = int(input())

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

    print(t)

if __name__ == "__main__":
    main()

import fractions

n = int(input())

t = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            ans = i
            ans = fractions.gcd(ans, j)
            ans = fractions.gcd(ans, k)
            t += ans

print(t)

from math import gcd

def main():
    n = int(input())

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

    print(t)

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):
from itertools import product
N = (input())
d = 0
res = [ele for ele in product(range(1,N+1),repeat=3)]
a =(res)
for i in a:
    if i[0]==i[1]==i[2]:
        d = d+i[0]
    else:
        d = d+1
print(d)


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


import math
a = int(input())
b = 0
for i in range(1,a+1):
    for j in range(1,a+1):
        c = math.gcd(i,j)
        for k in range(1,a+1):
            d = math.gcd(c,k)
            b +=d
print (b)

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())
gcdl = [[0 for i in range(k + 1)]for i in range(k+1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcdl[i][j] = gcd(i, j)
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            s += gcdl[i][gcdl[j][k]]

print(s)


from math import gcd
k = int(input())
gcdl = [[0 for i in range(k + 1)] for i in range(k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcdl[i][j] = gcd(i, j)
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            s += gcdl[i][gcdl[j][l]]

print(s)


Verdicts: Wrong Answer

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

Submission attempts (in order):
#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

K = int(input())

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

#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

K = int(input())

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

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

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

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 numpy as np

k = input()
sum = 0
for p in range(k):
    for q in range(k):
        for r in range(k):
            sum += np.gcd.reduce([i,j,k])

print(sum)

import math

k = int(input())
sum = 0
gcds = [[0 for i in range(k)] for i in range(k)]
for p in range(1,k+1):
    for q in range(1,k+1):   
        gcds[p-1][q-1] = math.gcd(p,q)          
        for r in range(1,k+1):
            sum += math.gcd(gcds[p-1][q-1], r)
            


print(sum)

Verdicts: Runtime Error

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

Submission attempts (in order):
import fractions
K=int(input())
ans=0
A=0

for n in range(1,K+1):
    for m in range(1,K+1):
      gcd1=fractions.gcd(n,m)
      for l in range(1,K+1):
          A=fractions.gcd(gcd1,l)   
          ans+=A
print(ans)


import fractions
K=int(input())
ans=0

for n in range(1,K+1):
    for m in range(1,K+1):
        for l in range(1,K+1):
            gcd=fractions.gcd(n,m)
            gcd=fractions.gcd(gcd,l)
            
            ans+=gcd
   
print(ans)


import fractions
K=int(input())
ans=0
 
for n in range(1,K+1):
    for m in range(1,K+1):
      gcd1=fractions.gcd(n,m)
      for l in range(1,K+1):
            gcd2=fractions.gcd(gcd1,l)
            
            ans+=gcd2
   
print(ans)

import fractions
K=int(input())
ans=0
 
for n in range(1,K+1):
    for m in range(1,K+1):
      gcd1=fractions.gcd(n,m)
      for l in range(1,K+1):
            ans+=fractions.gcd(gcd1,l)   
print(ans)

import fractions
K=int(input())
ans=0
 
for n in range(1,K+1):
    for m in range(1,K+1):
        for l in range(1,K+1):
            gcd=fractions.gcd(n,m)
            gcd=fractions.gcd(gcd,l)
            
            ans+=gcd
   
print(ans)


import math
K=int(input())
ans=0
A=0

for n in range(1,K+1):
    for m in range(1,K+1):
        x=math.gcd(n,m)
        for l in range(1,K+1):
            A=math.gcd(x,l)    
            ans+=A
            
print(ans)


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):
import math
import itertools
import numpy as np
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
list2 = []
result = 0
n = int(input())
for i in range(1,n+1):
    if(not(is_prime(i))):
        for j in range(1,n+1):
          for k in range(1,n+1):
#            list2.append([i,j,k])
#            result +=  np.gcd.reduce((i,j,k))
#            print(result ,i,k,j)
    else:
        result += n*n-1
for i in range(1,n+1):
    if(is_prime(i)):
        result += i
print(result)
#print(list2)

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


k = int(input()) + 1

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


from math import gcd 

num = int(input()) + 1

count = 0
for a in range(1, num):
    for b in range(1, num):
        t = gcd(a,b)
        for c in range(1, num):
                count += gcd(t, c)
print(count)


Verdicts: Wrong Answer

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

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

print(ans)

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

print(ans)

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

print(ans)

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

print(ans)

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

k = int(input())
sum = 0

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

print(sum)

from math import gcd

k = int(input())
num = 0

for a in range(0, k + 1):
  for b in range(0, k + 1):
    c = gcd(a, b)
    num += sum(gcd(c, d) for d in range(1, k + 1))

print(num)

import math
from functools import reduce

k = int(input())
sum = 0

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

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

print(sum)

import math
from functools import reduce

k = int(input())
sum = 0

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

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

print(sum)

import math

k = int(input())
num = 0

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

print(num)

from math import gcd

k = int(input())
num = 0

for a in range(1, k + 1):
  for b in range(1, k + 1):
    c = gcd(a, b)
    num += sum(gcd(c, d) for d in range(1, k + 1))

print(num)

Verdicts: Wrong Answer

Wrong Answer

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):
from math import gcd
k = int(input())+1
n = 0
for i in range(1,k):
  for j in range(i,k):
    for l in range(j, k):
      if i == j == l:
        print([i, j, l])
        print(gcd(i,gcd(j,l)))
        n += gcd(i,gcd(j,l))
      elif i == j or j == l or l == i:
        print([i,j,l])
        print(gcd(i,gcd(j,l))*3)
        n += gcd(i,gcd(j,l))*3
      else:
        print([i,j,l])
        print(gcd(i,gcd(j,l))*6)
        n += gcd(i,gcd(j,l))*6
print(n)

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

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

print(ans)

import math

k = int(input())
ans = 0
m = 0
for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1, k+1):
            m = math.gcd(a,b)
            ans += 6*math.gcd(m,c)
for a in range(1,k+1):
    for c in range(a+1,k+1):
        ans += 3*math.gcd(a,c)
for c in range(1,k+1):
    for a in range(c+1,k+1):
        ans += 3*math.gcd(a,c)
for a in range(1,k+1):
    ans += a
print(ans)

Verdicts: Runtime Error

Accepted