Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- GPU #cuda out of memory #gpu 메모리 #pytorch
- 백준 #알고리즘 #골드
- 파이썬 #Python
- docker #우분투 #ubuntu #도커 설치 #docker 설치 #docker installation #우분투 도커
- jupyter notebook #anaconda #vscode #pytorch #딥러닝 #deep learning #vscode server #서버 vscode #ssh vscode #vscode cuda
- logistic regression
- docker #아나콘다 #anaconda #ubuntu anaconda #docker anaconda
- 깃허브 #우분투 #ubuntu #Github #깃허브 우분투 #깃헙 우분투 #깃헙
- docker #cuda #docker container #도커 #도커 컨테이너 #쿠다 #cuda 11.3
- Machine Learning
- ssh #우분투 ssh #우분터 서버 #도커 #우분투 도커 #docker #cuda #우분투 개발환경 #딥러닝 #ubuntu docker #ubuntu cuda
- 백준
- 트랜스포머 #transformer #attention #self-attention #어텐션 #인공지능 #AI #딥러닝 #NLP #자연어처리
- 구름
- pytorch #cuda #우분투 torch #ubuntu pytorch #cuda torch #cuda pytorch
- 트랜스포머 #자연어처리 #딥러닝 #구글 #attention #self-attention #BERT #transformer #deeplearing
- BERT #구글BERT #BERT의정석
- 머신러닝
- 알고리즘 #levenshtein distance #편집거리 #edit distance
- 구름자연어처리과정
- pandas #folium #groupby #네이버부스트코스 #코칭스터디
- GPU #jtorch GPU #파이토치 병렬 #파이토치 GPU #pytorch gpu #multi process torch #horovod
- docker #도커 #도커 컨테이너 #docker container #도커 우분투
- cuda #centos #cuda삭제 #리눅스 #cenos cuda삭제
Archives
- Today
- Total
바닥부터 시작하는 개발 공부
[알고리즘]백준 1747: 소수&팰린드롬 본문
728x90
알고리즘 유형: 수학, 브루트포스
문제
어떤 수와 그 수의 숫자 순서를 뒤집은 수가 일치하는 수를 팰린드롬이라 부른다. 예를 들어 79,197과 324,423 등이 팰린드롬 수이다.
어떤 수 N (1 ≤ N ≤ 1,000,000)이 주어졌을 때, N보다 크거나 같고, 소수이면서 팰린드롬인 수 중에서, 가장 작은 수를 구하는 프로그램을 작성하시오.
입력
첫째 줄에 N이 주어진다.
출력
첫째 줄에 조건을 만족하는 수를 출력한다.
풀이
소수를 찾는 알고리즘+ 팰린드롬 수인지 확인하는 알고리즘이었습니다
이는 str(num)==str(num[::-1])로 확인 가능합니다
import sys
import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
r = int(math.sqrt(n))
f = 5
while f <= r:
if n % f == 0 or n % (f+2) == 0:
return False
f += 6
return True
N= int(sys.stdin.readline().strip())
for num in range(N, 100000000):
if is_prime(num)==True and str(num)==str(num)[::-1]:
print(num)
break
728x90
'Algorithm > 백준' 카테고리의 다른 글
[알고리즘]백준 9613: GCD합 (1) | 2023.02.24 |
---|---|
[알고리즘]백준 1235 : 학생 번호 (0) | 2023.02.24 |
[알고리즘]백준 2178번: 미로 탐색 (0) | 2023.02.21 |
[알고리즘]백준 1931번: 회의실 배정 (0) | 2023.02.21 |
[알고리즘]백준 1003번: 피보나치 함수 (0) | 2023.02.21 |
Comments