전체 글(331)
-
[BOJ] 11653번 : 소인수분해
1. problem : https://www.acmicpc.net/problem/11653 2. solution 1 :#include using namespace std;int n; vector prime_factor(int n) { vector ans; for (int i = 2; i * i > n; vector ans = prime_factor(n); for (auto p : ans) cout source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x12/solutions/11653.cpp basic-algo-lecture/0x12/solutions/11653.cpp at master · encrypted..
2024.09.22 -
[BOJ] 1929번 : 소수 구하기
1. problem : https://www.acmicpc.net/problem/1929 2. solution 1 :#include using namespace std;int n, m; vector eratos(int a) { vector primes; vector numbers(1000005, true); numbers[1] = false; for (int i = 2; i * i > n >> m; vector primes = eratos(m); for (auto p : primes) { if (n sieve of Eratosthenes를 이용해 풀었다. 아직 에라토스네스의 체가 이해가 가지는 않지만, 외워서 풀었다. 여기서 vector 을 이용하면, 공간 절약과 cache hit rate..
2024.09.22 -
[C++] Prime number
0. 합성수 N에서 1을 제외한 가장 작은 약수는 root(N)이하이다. 1. 1부터 n까지 모든 소수 찾기 #include using namespace std;vector isprime(int n) { vector primes; for (int i =2; i i) break; if (i % p == 0) { isprime = 0; break; } } if (isprime) primes.push_back(i); }}4 이상의 모든 합성수는 약수의 최솟값이 prime number다. 따라서, primes에 소수를 추가해 주면서, 소수판별을 진행한다. 2. 에라토테네스의 체 #..
2024.09.22 -
[BOJ] 1978번 : 소수 찾기
1. problem : https://www.acmicpc.net/problem/1978 2. solution 1 :#include using namespace std;int n; bool isprime(int a) { if (a == 1) return 0; for (int i = 2; i * i > n; int cnt = 0; for (int i = 0; i > x; cnt += isprime(x); } cout 소수를 찾기 위해서는 숫자 a가 있을 때, root(a)까지만 검사를 해보면 된다. 그 이유는 어떤 수 a의 1이 아닌 제일 작은 약수를 x라고 하자. 이때, a를 x로 나눈 값, 즉, (a / x)는 x보다 크거나 같은 값이 된다. 따라서, x
2024.09.22 -
[Git Bash] scp를 이용하여 파일 전송하기
0. vm 환경 local 저장소로 파일 전송하기 위해 Git Bash가 필요하다. https://git-scm.com/download/win 1. 설치가 끝났으면, git bash를 켜준다. vm ---> local로 파일 전송방법 scp [vm 주인 이름]@[vm ip]:/file/to/send/pathway/ [받고 싶은 local 저장소 위치]
2024.09.22 -
[BioPython] Bio.Phylo
0. Bio.Phylo 모듈은 계통을 그려주는 모듈이다. Bio.Phylo는 4개의 파일형식을 읽을 수 있다. Newick, Nexus, Phyloxml, Nexml 1. 사용법 from Bio import Phylotree = Phylo.read("../nwk/sample_tree1.nwk","newick")tree.rooted = Truetree.root.color = (128,128,128)print(tree)tree.clade[0].color = "blue"tree.clade[1].color = "red"tree.clade[2,0].color = "green"tree.clade[2,1].color = "green"Phylo.draw(tree, branch_labels = lambda c : c..
2024.09.22