Skip to content

Instantly share code, notes, and snippets.

@uchidama
Created July 14, 2021 02:10
Show Gist options
  • Save uchidama/651a8233487dbb8245eb3018fccd3639 to your computer and use it in GitHub Desktop.
Save uchidama/651a8233487dbb8245eb3018fccd3639 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 162 [ C - Sum of gcd of Tuples (Easy) ] https://atcoder.jp/contests/abc162/tasks/abc162_c
'''
[問題]
https://atcoder.jp/contests/abc162/tasks/abc162_c
'''
import sys
import functools
import math
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
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):
A = [i,j,k]
# Aの最大公約数を求める
gcd = functools.reduce(math.gcd, A)
ans += int(gcd)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment