SOLUTION INFO
C++ · main.cpp
- 작성자
- tony9402
- 공동 작성자
- 없음
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if(b == 0) return a;
return gcd(b, a%b);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
int a, b; cin >> a >> b;
a = gcd(a, b);
if(n == 3) {
int c; cin >> c;
a = gcd(a, c);
}
vector<int> ans;
for(int i=1;i*i<=a;i++){
if(a % i != 0) continue;
ans.push_back(i);
if(i * i != a) ans.push_back(a / i);
}
sort(ans.begin(), ans.end());
for(int i=0;i<(int)ans.size();i++){
cout << ans[i] << '\n';
}
return 0;
}
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.
SOLUTION INFO
Java · Main.java
- 작성자
- suin8
- 공동 작성자
- tony9402
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
FastReader rd = new FastReader();
int n = rd.nextInt();
int num1 = 0, num2 = 0, num3 = 0;
num1 = rd.nextInt();
num2 = rd.nextInt();
if(n == 3) {
num3 = rd.nextInt();
}
// 1부터 차례대로 2개 또는 3개의 숫자가 모두
// 나누어지면 공약수 => 출력
for(int i = 1;i <= num1; i++) {
if(num1 % i == 0 && num2 % i == 0 && num3 % i == 0)
System.out.println(i);
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.
SOLUTION INFO
Python · main.py
- 작성자
- gusdn3477
- 공동 작성자
- tony9402
import sys
def input():
return sys.stdin.readline().rstrip()
def GCD(x,y):
if y == 0:
return x
else:
return GCD(y, x%y)
n = int(input())
arr = list(map(int, input().split()))
outputs = list()
gcd = arr[0]
for i in range(1, n):
gcd = GCD(gcd, arr[i])
x = 1
while x * x <= gcd:
if gcd % x == 0:
outputs.append(x)
if x * x != gcd:
outputs.append(gcd // x)
x += 1
outputs.sort()
print(*outputs)
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.