문제 조건 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
문제 조건 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
마지막에 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; } ..
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
import java.math.BigInteger; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BigInteger A = sc.nextBigInteger(); BigInteger B = sc.nextBigInteger(); System.out.println(A.add(B)); } } int는 메모리 크기는 4byte로 표현할 수 있는 범위는 -2,147,483,648 ~ 2,147,483,647 이고 long은 메모리 크기는 8byte로 표현할 수 있는 범위는 -9,223,372,036,854,775,808 ~ 9,223,372,036,85..
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if(3
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i < T; i++) { int k = sc.nextInt(); int n = sc.nextInt(); System.out.println(howManyPeople(k, n)); } } public static int howManyPeople(int k, int n) { // 제한은 1
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i=0; i
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); // 낮에 올라갈 수 있는 거리 int b = sc.nextInt(); // 밤에 내려가는 거리 int v = sc.nextInt(); // 나무막대의 높이 int tot = a-b; // 하루에 이동하는 거리 // 정상에 올라간 후에는 미끄러지지 않는다고 했기 때문에 // v에서 a 거리를 먼저 빼주고 계산 v = v - a; // 위에서 마지막 하루 이동하는 거리를 빼고 계산했기 때문에 결과에 하루를 더해줌. // 딱 나누어 떨어질 경우에는 +1 if(v ..
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x= sc.nextInt(); int tmp=0, cross_line=0; // 대각선 줄로 보면 줄하나가 생길때마다 원소가 1개씩 늘어나는 걸 볼 수 있음 // 대각선 줄 구하는 방법 for(int i=1; i= x) { cross_line=i; break; } } // 대각선 줄이 홀수/짝수 개수일 때 해당하는 원소 값 구하는 방법 if(cross_line % 2 == 1) System.out.println((1+tmp-x) + "/" + (cross_line-(tmp-x))); else..