[java] 백준 2581번 소수
알고리즘/백준2021. 7. 25. 14:30[java] 백준 2581번 소수

문제 조건 1. M이상 N이하의 자연수 중 소수인 것을 모두 찾아 첫째 줄에 합 2. 둘째 줄에 1번 조건의 소수 중 최솟값 출력 3. M이상 N이하의 자연수 중 소수가 없을 경우 첫째 줄에 -1 출력 import java.util.Scanner; // 2581 class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int M = sc.nextInt(); int N = sc.nextInt(); int[] arr = new int[N]; int count, tot=0, sosuCount=0; for(int i=M; i

[java] 백준 11653번 소인수분해
알고리즘/백준2021. 7. 24. 12:15[java] 백준 11653번 소인수분해

문제 조건 1. 소인수 분해 결과를 한 줄에 하나씩 오름차순으로 출력 (1,2,3 ~~) 2. N이 1인 경우 아무것도 출력 안함 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if(N == 1) { sc.close(); } for(int i=2; i

[java] 백준 4153번 직각삼각형
알고리즘/백준2021. 7. 23. 21:14[java] 백준 4153번 직각삼각형

마지막에 0 0 0 을 입력시켰을 때 반복문을 종료 시켜주면 되겠다 싶어 이런식으로 구현을 했고 Math.pow 함수를 쓰면 ex) Math.pow(3,2) => 3의 제곱인 9가 나오는 것이다. 그래서 아래와 같이 코드를 작성했다. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true){ int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); // 입력이 0 0 0 일때 반복문 탈출 if(a == 0 && b == 0 && c == 0){ break; } ..

[java] 백준 1978번 소수 찾기
알고리즘/백준2021. 7. 22. 21:09[java] 백준 1978번 소수 찾기

import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int sosu=0; for(int i=0; i

image