전체 글(108)
-
[BOJ] 백준 2981 검문 Python
#2981 검문 import sys import math input = sys.stdin.readline N = int(input()) A = [] for i in range (0,N): a = int(input()) A.append(a) A = list(set(A)) B = [] for i in range (0,len(A)-1): for j in range (i+1,len(A)): b = A[j] - A[i] B.append(b) gcd = B[0] for i in range (1,len(B)): gcd = math.gcd(gcd,B[i]) gcd = math.fabs(gcd) result = [] for i in range (1,int(math.sqrt(gcd))+1): if gcd % i == 0:..
2023.10.27 -
[BOJ] 백준 1684 같은 나머지 Python
#1684 같은 나머지 import sys import math input = sys.stdin.readline N = int(input()) A = list(map(int,input().split())) #혹시 모를 중복을 미리 set을 사용하여 제거# A = list(set(A)) B = [] for i in range (0,len(A)-1): for j in range (i+1,len(A)): b = A[j] - A[i] B.append(b) gcd = B[0] for i in range (1,len(B)): gcd = math.gcd(gcd,B[i]) print(gcd) 나머지가 같게 된다는 것에서 착목할 수 있는 간단한 문제
2023.10.27 -
[BOJ] 백준 1016 제곱ㄴㄴ수 Python
#1016 제곱 ㄴㄴ수 import sys import math A,B = map(int,input().split()) C = int(math.sqrt(B)) nest = [1] * (B-A+1) for i in range (2,C+1): a = A // (i ** 2) a *= (i ** 2) if a * (i ** 2) = 0: nest[j-A] = 0 print(nest.count(1)) 이것도 좀 나중에 설명을 좀 써둬야겠네요 ㅋㅋ ㅠ
2023.10.27 -
[BOJ] 백준 1463 1로 만들기 Python
#1463 1로 만들기 import sys import math input = sys.stdin.readline N = int(input()) #0,1,2,3으로부터 최단거리로 1을 만드는 방법# dp = [0,0,1,1] for x in range (4,N+1): if x % 2 != 0 and x % 3 != 0: y = dp[x-1] + 1 dp.append(y) elif x % 2 != 0 and x % 3 == 0: y = min(dp[x//3],dp[x-1]) + 1 dp.append(y) elif x % 2 == 0 and x % 3 != 0: y = min(dp[x//2],dp[x-1]) + 1 dp.append(y) else: y = min(dp[x//2],dp[x//3],dp[x-1])..
2023.10.27 -
[BOJ] 백준 1790 수 이어 쓰기2 Python
#1790번 수 이어쓰기 2 import sys import math input = sys.stdin.readline N,k = map(int,input().split()) a = len(str(N)) length_N = 0 #출력 가능인가 판정# if a == 1: length_N += N else: for i in range (1,a+1): length_N += 9 * (10 ** (i-1)) * i length_N += (N - (10 ** a) + 1) * a #몇번째 digit에 포함되는지 확인 digit = 1 length = 1 while True: if length
2023.10.27 -
[BOJ] 백준 2877 4와 7 Python
#2877번 4와 7 import sys import math input = sys.stdin.readline N = int(input()) digit = 1 word = [] while True: if 2**(digit) - 1
2023.10.27