Computer Science7 [Python] 약수와 소인수분해를 이용한 최대공약수 구하기 두 수 X와 Y의 최대공약수를 어떻게 구할 수 있을까? 1. X와 Y의 모든 약수를 구한 다음 공통되는 약수 중 가장 큰 수를 찾아내면 된다. 2. X와 Y를 소인수분해한 다음 공통되는 인수를 모두 곱해서 구한다. -1번 방법 def divisors(n): div = [] for i in range (1, n + 1): if (n % i == 0): div.append(i) return div def commons(n, m): comm = [] for i in n: if(i in m): comm.append(i) return comm def gcd(n, m): div_n = divisors(n) div_m = divisors(m) comm = commons(div_n, div_m) return comm[.. 2022. 5. 3. C++ -5- 홀수 짝수 판별 프로그램 #include using namespace std; int main() { while(1) { int a; cin >> a; if (a % 2 == 0) cout 2021. 4. 7. C++ -4- While 반복문과 함수를 이용한 간단한 덧셈 계산기 #include using namespace std; int plus5(int num_a, int num_b) { int sum = num_a + num_b; return sum; } int main() { while (1) { int x, y; cin >> x >> y; cout 2021. 4. 5. C++ -3- 함수와의 첫 만남 #include using namespace std; int multiplyNumbers(int num_a, int num_b) { int sum = num_a * num_b; return sum; } int main() { cout 2021. 4. 5. 이전 1 2 다음