본문 바로가기

분류 전체보기

(61)
[백준] 11005번 (python 파이썬) https://www.acmicpc.net/problem/11005 11005번: 진법 변환 2 10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를 www.acmicpc.net number, base = map(int, input().split()) t = number result = [] while t != 0: t, r = divmod(t, base) if r >= 10: r = ord("A") + (r-10) result.append(chr(r)) else: result.append(str(r)) print("".join(reversed(result)))
[백준] 17103번 (python 파이썬) https://www.acmicpc.net/problem/17103 17103번: 골드바흐 파티션 첫째 줄에 테스트 케이스의 개수 T (1 ≤ T ≤ 100)가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 정수 N은 짝수이고, 2 < N ≤ 1,000,000을 만족한다. www.acmicpc.net import sys arr = [True]*1000001 arr[0] = arr[1] = False for i in range(2, 1001): if arr[i]: for j in range(i+i, 1000001, i): arr[j] = False testcase = int(sys.stdin.readline()) for _ in range(testcase): number = int(sys.stdi..
[백준] 2089번 (python 파이썬) https://www.acmicpc.net/problem/2089 2089번: -2진수 -2진법은 부호 없는 2진수로 표현이 된다. 2진법에서는 20, 21, 22, 23이 표현 되지만 -2진법에서는 (-2)0 = 1, (-2)1 = -2, (-2)2 = 4, (-2)3 = -8을 표현한다. 10진수로 1부터 표현하자면 1, 110, 111, 100, 101, 11010, 110 www.acmicpc.net number = int(input()) if number == 0 : print(0) else: d = number result = "" while d != 1: r = d % -2 d = d // -2 if r < 0: d += 1 r *= (-1) result += str(r) else: resu..
[백준] 1212번 (python 파이썬) https://www.acmicpc.net/problem/1212 1212번: 8진수 2진수 첫째 줄에 8진수가 주어진다. 주어지는 수의 길이는 333,334을 넘지 않는다. www.acmicpc.net print(bin(int(input(),8))[2:]) 또는 print(format(int(input(),8),'b')) 파이썬에서는 강력한 내장함수가 주어진다.
[백준] 1373번 (python 파이썬) https://www.acmicpc.net/problem/1373 1373번: 2진수 8진수 첫째 줄에 2진수가 주어진다. 주어지는 수의 길이는 1,000,000을 넘지 않는다. www.acmicpc.net print(oct(int(input(),2))[2:]) 파이썬에서는 강력한 내장함수가 제공된다.
[백준] 17087번 (python 파이썬) https://www.acmicpc.net/problem/17087 17087번: 숨바꼭질 6 수빈이는 동생 N명과 숨바꼭질을 하고 있다. 수빈이는 현재 점 S에 있고, 동생은 A1, A2, ..., AN에 있다. 수빈이는 걸어서 이동을 할 수 있다. 수빈이의 위치가 X일때 걷는다면 1초 후에 X+D나 X-D로 이 www.acmicpc.net import sys def get_gcd(num1, num2): while num2 != 0: r = num1 % num2 num1 = num2 num2 = r return num1 _, S = map(int, input().split()) arr = list(map(int, sys.stdin.readline().split())) arr = set(map(lambd..
[백준] 9613번 (python 파이썬) https://www.acmicpc.net/problem/9613 9613번: GCD 합 첫째 줄에 테스트 케이스의 개수 t (1 ≤ t ≤ 100)이 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있다. 각 테스트 케이스는 수의 개수 n (1 < n ≤ 100)가 주어지고, 다음에는 n개의 수가 주어진 www.acmicpc.net import itertools import sys def get_gcd(n, m): while m != 0: r = n % m n = m m = r return n testcase = int(sys.stdin.readline().strip()) for _ in range(testcase): arr = list(map(int, sys.stdin.readline().split(..
[백준] 2004번 (python 파이썬) https://www.acmicpc.net/problem/2004 2004번: 조합 0의 개수 첫째 줄에 정수 $n$, $m$ ($0 \le m \le n \le 2,000,000,000$, $n \ne 0$)이 들어온다. www.acmicpc.net n, m = map(int, input().split()) def get_count(n, k): count = 0 while n: n = n // k count += n return count result = min(get_count(n, 2) - get_count(n-m, 2) - get_count(m, 2),\ get_count(n, 5) - get_count(n-m, 5) - get_count(m, 5)) print(result) n! 에서 끝자리 0..