Problem:


Score : 300 points

Problem Statement

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.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692



Sample input:
2


Sample output:
9

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import lru_cache
 
def main():
    K = int(input()) + 1
 
    @lru_cache(maxsize=1000)
    def get_gcd(a, b, c):
        tmp = gcd(a, b)
        return gcd(tmp, c)
 
    memo = set()
    result = 0
    for c in range(1, K):
        for b in range(1, K):
            for a in range(1, K):
                    result += get_gcd(a, b, c)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

# input
K = int(input())

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

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

# output
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = (1+N)*N // 2
s1 = 0
s2 = 0
s3 = 0
if N >= 3:
    s1 = ((3 + (N//3)*3) * (N//3)) // 2
if N >= 5:
    s2 = ((5 + (N//5)*5) * (N//5)) // 2
if N >= 15:
    s3 = ((15 + (N//15)*15) * (N//15)) // 2
print(s + s3 - s1 - s2)

Submission status: Wrong Answer

Solution code:
import math
K=int(input())
out=int(0)
if K<3:
    for i in range (1,K+1):
        for j in range (1,K+1):
            for k in range (1,K+1):
                out=out+math.gcd(math.gcd(i,j),k)
else:
    out = out + K*(K+1)/2
    for i in range (1,K):
        for j in range (i+1,K):
            out = out+6*math.gcd(i,j)

    for i in range (1,K-1):
        for j in range (i+1,K):
            for k in range (j+1,K+1):
                out=out+math.gcd(math.gcd(i,j),k)
print(int(out))

Submission status: Wrong Answer

Solution code:
k = int(input())
ans = []
for a in range(1,k+1) :
    for b in range(1, k+1):
        for c in range(1, k+1):
            if a == b and b == c :
                ans.append(a)
            else:
                ans.append(1)

print(sum(ans))

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce

K = 200

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import lru_cache
 
def main():
    K = int(input()) + 1
 
    @lru_cache(maxsize=1000)
    def get_gcd(a, b, c):
        tmp = gcd(a, b)
        return gcd(tmp, c)
 
    memo = set()
    result = 0
    for c in range(1, K):
        for b in range(1, K):
            for a in range(1, K):
                    result += get_gcd(a, b, c)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import functools
import itertools


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


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


K = int(input())

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

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
from itertools import product
import numpy

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

n = int(input())

l = product(range(1, 1+n), repeat=3)

print(numpy.cumsum([gcd(*i) for i in l]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a=1
b=1
c=1
num=0
s=1
for d in range(1,c+1) :
  for e in range(1,b+1) :
    for f in range(1,c+1) :
      for x in range(1,max(a,b,c)+1) :
        if n%x == 0 :
          s=x
      num += s
      s=1
print(str(num))

Submission status: Wrong Answer

Solution code:
N = int(input()) + 1


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


def find_gcd(arr):
    result = arr[0]

    for i in range(1, len(arr)):
        result = gcd(arr[i], result)

        if result == 1:
            return 1
    return result


ans = 0
table = {}
for a in range(1, N):
    for b in range(1, N):
        for c in range(1, N):
            if a == b == c:
                ans += a
            else:
                key = ''.join(sorted([str(a), str(b), str(c)]))
                if key in table:
                    ans += table[key]
                else:
                    table[key] = find_gcd([a, b, c])
                    ans += table[key]
                print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
import math
from functools import reduce

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


k = int(input())
a = np.array(range(1, k+1))
#print(a)

comb = list(itertools.combinations_with_replacement(a, 3))
#print(comb)


ans = 0
for elm in comb:
    if elm[0] == elm[1] == elm[2]:
        #print(elm)
        ans += gcd(elm[0], elm[1], elm[2])
    else:
        ans += gcd(elm[0], elm[1], elm[2]) * 3
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools


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


k = int(input())
items = list(range(1, k+1))
ans = 6 * sum(items)
ans += sum([6 * gcd_list(item) for item in itertools.combinations(items, 2)])
ans += sum([6 * gcd_list(item) for item in itertools.combinations(items, 3)])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
sum=0
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
from itertools import product
pools = product(range(N),range(N),range(N))
for i, j ,k in pools:
  sum =sum + gcd(i, j, k)
print(sum)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce


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

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

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

print(sum)

Submission status: Wrong Answer

Solution code:
def gcd(x, y): 
   while y: 
       x, y = y, x % y 
   return x 

k = int(input())

result = 0
cache = {}
for x in range(1, k+1):
    for y in range(1, k+1):
        for z in range(1, k+1):
            tup = tuple(sorted((x, y, z)))
            if tup in cache:
                result += cache[tup]
            else:
                cache[tup] = gcd(x, gcd(y, z))
                result += cache[tup]
            result += gcd(x, gcd(y, z))
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
import math
from functools import reduce

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


k = int(input())
a = np.array(range(1, k+1))
#print(a)

comb = list(itertools.combinations_with_replacement(a, 3))
#print(comb)


ans = 0
for elm in comb:
    if elm[0] == elm[1] == elm[2]:
        print(elm)
        ans += gcd(elm[0], elm[1], elm[2])
    else:
        ans += gcd(elm[0], elm[1], elm[2]) * 3
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ki = int(input())

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

sum = 0
for i in range(1,ki+1):
    for j in range(1,ki+1):
        for k in range(1,ki+1):
            tk = gcd(i,j)
            tr = gcd(tk,k)
            sum +=tr

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
from itertools import product
import numpy

n = int(input())

l = product(range(1, 1+n), repeat=3)
# print(l)

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

print(numpy.cumsum([gcd(*i) for i in l]))

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
K = int(input())
sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            nums = [a, b, c]
            gcd = reduce(math.gcd, nums)
            print(a, b, c, gcd)
            sum += gcd
print(sum)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import lru_cache
 
def main():
    K = int(input()) + 1
 
    @lru_cache(maxsize=1000)
    def get_gcd(a, b, c):
        tmp = gcd(a, b)
        return gcd(tmp, c)
 
    memo = set()
    result = 0
    for c in range(K):
        for b in range(K):
            for a in range(K):
                    result += get_gcd(a, b, c)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
k=int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for l in range(j,k+1):
      if l==i:
        ans+=gcd(i,j,l)
      elif i==j or j==l:
        ans+=2*gcd(i,j,l)
      else:
        ans+=gcd(i,j,l)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import math
K=int(input())
A=[]
for i in range(1,K+1):
  A.append(i)

 
ans=0
for a,b,c in (itertools.product(A,A,A)):
    print(a,b,c)
    x=math.gcd(a,b)
    y=math.gcd(x,c)
    ans +=y
    
 
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

def gcd(a, b, c):
    ab = math.gcd(a, b)
    bc = math.gcd(b, c)
    ca = math.gcd(c, a)
    return min([ab, bc, ca])

num = int(input())

arr = list(range(1, num + 1))
# 3種の数字
tri = itertools.combinations(arr, 3)
sum_tri = sum([gcd(t[0], t[1], t[2]) for t in tri])
# 2種の数字
di = itertools.combinations(arr, 2)
sum_di = 6 * sum([math.gcd(d[0], d[1]) for d in di])
# 1種
single = sum(arr)
print(sum_tri, sum_di, single)
print(sum_tri + sum_di + single)

Submission status: Wrong Answer

Solution code:
from math import gcd
from functools import lru_cache

def main():
    K = int(input()) + 1

    @lru_cache(maxsize=1000)
    def get_gcd(a, b, c):
        tmp = gcd(a, b)
        return gcd(tmp, c)

    memo = set()
    result = 0
    for c in range(K):
        for b in range(K):
            for a in range(K):
                    result += get_gcd(a, b, c)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
add=0
for i in range(n):
    for j in range(n):
        for k in range(n):
            add+=math.gcd(math.gcd(i,j),k)
print(add)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

def gcd(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp

    r = a % b
    while r!=0:
        a = b
        b = r
        r = a % b
    return b

def gcd_three(a, b, c):
    temp = gcd(a, b)
    return gcd(temp, c)

K = int(input())
ans = 0

ans += sum(range(1, K+1))

two_Ns = combinations(range(1, K+1), 2)
ans += 3*sum([gcd(*t) for t in two_Ns])

three_Ns = combinations(range(1, K+1), 3)
ans += 6*sum([gcd_three(*t) for t in three_Ns])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [[0]* 201]*201

def gcd (a,b):
  if L[a][b] != 0:
    return L[a][b]
  if a < b:
    A, B = b, a
  else:
    A, B = a, b
  while b:
    a,b = b, a % b
  L[A][B] = a
  return a
print (sum([gcd(gcd(x,y),z) for x in range(1,N+1)  for y in range(1,N+1)  for z in range(1,N+1)]))

Submission status: Wrong Answer

Solution code:
def gcd(x,y,z):
  p=[x,y,z]
  p.sort()
  a=p[0]
  b=p[1]
  while a!=0 and b!=0:
    b-=a
    if a>b:
      c=b
      b=a
      a=c
  ee=[a,b]
  ee.sort()
  if p[2]%ee[1]==0:
    return(ee[1])
  else:
    return(1)
n=int(input())
s=0
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      s+=gcd(i,j,k)
print(s)

Submission status: Wrong Answer

Solution code:
import itertools
import math
K=int(input())
A=[]
for i in range(1,K+1):
  A.append(i)

 
ans=[]
for a,b,c in (itertools.product(A,A,A)):
    print(a,b,c)
    x=math.gcd(a,b)
    y=math.gcd(x,c)
    ans.append(y)
    
 
    
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import fractions

n=int(input())

sum = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            sum += fractions.gcd(i,fractions.gcd(j,k))

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


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

def main():
    k=int(input())
    a=0
    b=0
    ans = 0

    w = [[0]*(k+1) for _ in range(k+1)]
    for i in range(1,k+1):
        for j in range(i,k+1):
            w[i][j] = gcd(i,j)

    for i in range(1,k+1):
        for j in range(i,k+1):
            for k in range(j,k+1):
                s =set([i,j,k])
                length = len(s)
                if length == 1:
                    ans += i
                elif length == 2:
                    l = list(s)
                    ans += 3*w[l[0]][l[1]]
                else:
                    a = w[i][j]
                    b = w[a][k]
                    ans += 6*b

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
K=int(input())
import math

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

Submission status: Wrong Answer

Solution code:
import fractions;

N=int(input())

#ことなる３つ
cnt1=0
for i in range(1, N+1-2):
    for j in range(i+1, N+1-1):
        for k in range(j+1, N+1):
            #print('i='+str(i)+' j='+str(j)+' k='+str(k))
            A=fractions.gcd(i,j)
            B=fractions.gcd(A,k)
            cnt1+=B

#ことなる２つ
cnt2=0
for i in range(1, N+1-1):
    for j in range(i+1, N+1):
        cnt2+=fractions.gcd(i,j)*6

cnt3=0
for i in range(1, N+1):
    cnt3+=i
    
print(cnt1+cnt2+cnt3)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
k = int(input())

sum = 0
for x1 in range(1,k+1):
  for x2 in range(x1+1,k+1):
    for x3 in range(x2+1,k+1):
      for i in range(1, 2):
        ans = fractions.gcd(x1,x2)
        ans = fractions.gcd(ans,x3)
        sum += ans

print(sum*3)

Submission status: Wrong Answer

Solution code:
import math

K=2
count = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            _z=math.gcd(a,b)
            if a==b and b==c:
                k=1
            else:
                k=3
            count += k * math.gcd(_z,c)
print(count)

Submission status: Wrong Answer

Solution code:
import math

K=2
count = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            print(a,b,c)
            _z=math.gcd(a,b)
            if a==b and b==c:
                k=1
            else:
                k=3
            count += k * math.gcd(_z,c)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
gcd_sum_of_2 = 9
if N == 1:
    print(1)
elif N == 2:
    print(gcd_sum_of_2)
else:
    M = N - 2
    for i in range(M):
        gcd_sum_of_2 += (i + 2) * 3 + i + 3
    print(gcd_sum_of_2)

Submission status: Wrong Answer

Solution code:
from math import gcd

K = int(input())

if K == 1:
    print(1)
    exit()

ans = 3*(K-1)**2

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

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd_base(a, b):
    while b!=0:
        a, b = b, a%b
    return a

def gcd(num_list):
    ans = 0
    for i in num_list:
        ans = gcd_base(ans, i)
    return ans

k = int(input())
ans = 0
for i in range(1, k-1):
    for j in range(i+1, k):
        for l in range(j+1, k+1):
            ans += 6*gcd([i,j,k])
for i in range(1, k):
    for j in range(i+1, k+1):
        ans += 3*gcd_base(i, j)
for i in range(1, k+1):
    ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
  
k = int(input())
k+=1

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

Submission status: Wrong Answer

Solution code:
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

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

Submission status: Wrong Answer

Solution code:
n=int(input())
def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)
l=[]
tot=0
val=0
for i in range(1,n+1):
    ar=[]
    for j in range(1,n+1):
        ar.append(gcd(i,j))
    l.append(ar)
        
print(tot)

Submission status: Wrong Answer

Solution code:
import math
sum=0
num=int(input())
for a in range(num):
  for b in range(num):
    for c in range(num):
      d=math.gcd(a,b)
      e=math.gcd(c,d)
      sum=sum+e
print(sum)

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
mod2 = 2**61 + 1
int1 = lambda x: int(x) - 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
import itertools


# input = sys.stdin.readline
def input():
    return sys.stdin.readline().strip("\n").strip(" ")


_NUMINT_ALL = list(range(10))
_START_TIME = time.time()
INDEX_KETA = 10**12
INF = 9223372036854775807  # 符号つきlong longの最大値。10の18乗より大きく、10の19乗より小さい

def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is None:
        return

    if isinstance(ans, tuple):
        split_print_space(ans)
    else:
        print(ans)


def solve():
    K = iip()
    ans = 0

    t = time.time()
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                a = saidai_kouyakusuu([i, j, k])
                ans += a

    print(time.time() - t)

    print(ans)



#####################################################ライブラリ集ここから


def kiriage_warizan(a, b):
    return -(-a // b)


def iip(listed=False):  # 数字のinputをlistで受け取る
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1 and listed is False:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def iipt(l, listed=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    if isinstance(l, list):
        l = l[0]  # 間違って要素１個のタプルを渡されても受け取る
    assert isinstance(l, int)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def flatten(l):
    return list(itertools.chain.from_iterable(l))


def index_sorted(sorted_list, target):
    idx = bisect_left(sorted_list, target)
    if idx != len(sorted_list) and sorted_list[idx] == target:
        return idx
    else:
        return False


def time_debug_10percent():
    a = random.randint(0, 9)
    if a == 9:
        sys.exit()


def time_debug(t):
    time.sleep(_START_TIME + t - time.time())
    sys.exit()


def make_graph_edge_flat(N):  # グラフ作成のための辺をリストで返す
    ret = []
    for i in range(N - 1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x:x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x:x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):  # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    if isinstance(s, int):
        print(s)
        return
    keta = max([len(str(i)) for i in itertools.chain.from_iterable(s)])
    print("--------")
    for i in s:
        print([str(j).rjust(keta) for j in i])
    print("--------")


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2**N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret


def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n**0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  # modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_)**2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left", seido=1):  # 関数を二分探索
    l = left
    r = right
    if seido == 1:
        x = (l + r) // 2
    else:
        x = (l + r) / 2
    while r - l > seido:
        # print(x)
        if seido == 1:
            x = (l + r) // 2
        else:
            x = (l + r) / 2
        if func(x) == target:
            if side == "left":
                r = x
            else:
                l = x


        elif func(x) > target:
            r = x
        else:
            # print(r, l)
            l = x

    # print(l, r)
    if side == "left" and func(r) == target:
        return r
    elif side != "left" and func(l) == target:
        return l
    elif side == "left":
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  # リストを二分探索
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r - l > 1:
        x = (l + r) // 2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                # for i in path: # 経路圧縮
                #    self.parent[i] = cur
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def bs(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    return high

l = [1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
memo = [[[-1 for _ in range(201)] for _ in range(201)] for _ in range(201)]
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):
            a = sorted([i, j, k])
            if(memo[a[0]][a[1]][a[2]] != -1):
                ans += memo[a[0]][a[1]][a[2]]
            else:
                b = bs(l, a[0])
                for m in range(b, -1, -1):
                    if i % l[m] == 0 and j % l[m] == 0 and k % l[m] == 0:
                        ans += l[m]
                        memo[a[0]][a[1]][a[2]] = l[m]
                        break
            
            

print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())
ans = 0

def by8(n,ans):
    n = n-1
    if n > 1:
        ans += (n*7)
        ans = by8(n,ans)
    elif n == 1:
        ans += (n*7)
    return(ans)


ans = 0
ans = by8(k,ans)
ans += k
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = 2
sum = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            sum += math.gcd(math.gcd(k,j), i)

print(sum)

Submission status: Wrong Answer

Solution code:
import math

def gcd(A,B,C):
    output = 1
    maxi = max(A,B,C)
    maximum = math.sqrt(maxi)
    maxim = round(maximum)+1
    for i in range(maxim,1,-1):
        if ((A%i == 0) and (B%i == 0) and (C%i == 0)):
            output = i
            break
    return output

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 = sum + gcd(A,B,C)
print(sum)

Submission status: Wrong Answer

Solution code:
from itertools import product

K = int(input())

number = [i for i in range(1, K+1)]
comb = list(product(number, repeat=3))

amount = 0
for a, b, c in comb:
    if a <= b <= c:
        if a == b and b == c:
            amount += a
        elif a == b or b == c:
            a_k, c_k = a, c
            count = 1
            for i in range(2, int(a**0.5)+1):
                while a_k % i == 0 and c_k % i == 0:
                    count = count * i
            amount += count * 3
        else:
            a_k, b_k, c_k = a, b, c
            count = 1
            for i in range(2, int(a**0.5)+1):
                while a_k % i == 0 and b_k%i == 0 and c_k % i == 0:
                    count = count * i
            amount += count * 6

print(amount)

Submission status: Wrong Answer

Solution code:
import math

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