1. Problem
2. My Solution
import sys
import itertools
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
test_n = int(sys.stdin.readline().rstrip())
for _ in range(test_n):
test_case = list(map(int,sys.stdin.readline().rstrip().split()))
pair = list(itertools.combinations(test_case[1:],2))
sum = 0
for i in pair:
result = gcd(max(i), min(i))
sum += result
print(sum)
3. Learned
1. Problem
2. My Solution
import sys
n,s = map(int,sys.stdin.readline().rstrip().split())
loc_list = list(map(int,sys.stdin.readline().rstrip().split()))
d_list = []
for i in range(len(loc_list)):
d = abs(loc_list[i] - s)
d_list.append(d)
result = min_d = min(d_list)
for i in range(len(loc_list)):
if abs(loc_list[i] - s) % min_d != 0:
result = 1
print(result)
// 반례
3 2
6 12 24
1 (2가 나와야 정답)
import sys
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b, a%b)
n,s = map(int,sys.stdin.readline().rstrip().split())
loc_list = list(map(int,sys.stdin.readline().rstrip().split()))
d_list = []
for i in range(len(loc_list)):
d = abs(loc_list[i] - s)
d_list.append(d)
result = min_d = min(d_list)
for i in range(len(loc_list)-1):
temp= gcd(abs(loc_list[i]-s), abs(loc_list[i+1]-s))
if result > temp:
result = temp
print(result)
3. Learned
1. Problem
2. My Solution
import sys
binum = list(map(int,sys.stdin.readline().rstrip()))
if len(binum) % 3 == 1:
binum.insert(0,0)
binum.insert(0,0)
elif len(binum) % 3 == 2:
binum.insert(0,0)
weight = 4
sum = 0
result =''
for i in range(len(binum)):
sum += binum[i] * weight
weight = weight // 2
if weight == 0:
weight = 4
result += str(sum)
sum = 0
print(result)
3. Others' Solutions
print(oct(int(input(),2))[2:])
4. Learned