회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
(JAVA) 이 두 코드는 왜 틀린걸까요?
2436번 - 공약수
kus9087
3년 전
0
아래 두 코드도 반례 넣었을때 다 맞게 나왔는데 왜 틀린건지 모르겠습니당..
//=====================================정답코드========================================= //===================================================================================== import java.io.*; import java.math.*; public class Main { static int check(long a, long b) { int m = (int) (a % b); if (m == 0) return (int) b; return check(b, m); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); String inp[] = br.readLine().split(" "); int a = Integer.parseInt(inp[0]); int b = Integer.parseInt(inp[1]); long mul = (long) a * (long) b; long res1 = 0, res2 = 0; for (int i = a; i <= Math.sqrt(mul); i += a) { if (mul % i == 0 && check(i, mul / i) == a) { res1 = i; res2 = mul / i; } } bw.write(res1 + " " + res2); bw.flush(); bw.close(); } } //========================== 97%에서 틀림 ========================================== //================================================================================= import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); String inp[] = br.readLine().split(" "); int a = Integer.parseInt(inp[0]); int b = Integer.parseInt(inp[1]); ArrayList<Integer> list = new ArrayList<>(); for (int i = 1; i <= (int) Math.sqrt(b); i++) { if (b % i == 0) { int temp = b / i; if (i % a == 0) list.add(i); if (temp % a == 0 && temp != i) list.add(temp); } } Collections.sort(list); int res1 = 1000000000; int res2 = 1000000000; for (int i = 0; i < list.size(); i++) { for (int j = i + 1; j < list.size(); j++) { boolean pass = false; int t1 = list.get(i); int t2 = list.get(j); int gcd = 0; for (int k = a+1; k <= t1 ; k++) { if (t1 % k == 0 && t2 % k == 0) { pass = true; break; } } if (pass) continue; int lcm = 0; for (int k = t2; k <= b; k += t2) { if (k % t1 == 0) { lcm = k; break; } } if (lcm != b) continue; if (res1 + res2 > t1 + t2) { res1 = t1; res2 = t2; } } } bw.write(res1 + " " + res2); bw.flush(); bw.close(); } } //=====================================아예틀림============================================= //========================================================================================= import java.io.*; import java.math.*; public class Main { static boolean check(long a, long b) { //서로소 체크 for (long i = 2; i <= a; i++) { if (a % i == 0 && b % i == 0) return false; } return true; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); String inp[] = br.readLine().split(" "); int a = Integer.parseInt(inp[0]); int b = Integer.parseInt(inp[1]); long mul = (long)a * (long)b; long res1 = 0, res2 = 0; for (int i = a; i <= Math.sqrt(mul); i += a) { if (mul % i == 0 && check(i / a, (mul / i) / a)) { res1 = i; res2 = mul / i; } } bw.write(res1 + " " + res2); bw.flush(); bw.close(); } }
댓글을 작성하려면
로그인
해야 합니다.
kus9087 3년 전
아래 두 코드도 반례 넣었을때 다 맞게 나왔는데 왜 틀린건지 모르겠습니당..