1 | 1978 | ์์ ์ฐพ๊ธฐ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
int count = 0;
for(int t = 0; t<T; t++) {
int n = scan.nextInt();
if(n==1) continue;
else if(n==2) count++;
else {
for(int i=2; i<n; i++) {
if(n%i == 0) break;
if(i == n-1) count++;
}
}
}
System.out.println(count);
scan.close();
}
}
2 | 2581 | ์์ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int M = scan.nextInt();
int N = scan.nextInt();
scan.close();
int array[] = new int[N-M+1];
int count = 0;
int sum = 0;
if(M==1 && N ==1);
else if((M==2 || M ==1) && N==2) {
array[0] = 2;
count++;
}
else {
for(int i =M; i<= N; i++) {
if(i==1) continue;
else if (i==2) {
array[count] = 2;
count++;
continue;
}
for(int j=2; j<i; j++) {
if(i%j ==0 ) break;
if(i ==j+1) {
array[count] = i;
count++;
}
}
}
}
if(count == 0) System.out.println(-1);
else {
for(int i =0; i<array.length; i++) {
sum += array[i];
}
System.out.println(sum);
System.out.println(array[0]);
}
}
}
3 | 11653 | ์์ธ์๋ถํด |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
scan.close();
if(N == 1 );
else if(N==2) System.out.println(2);
else {
for(int i=2; i<N; i++) {
if(N%i == 0) {
System.out.println(i);
N = N/i;
i = 1;
if(N==1) break;
}
if(i == N-1) System.out.println(N);
}
}
}
}
4 | 1929 | ์์ ๊ตฌํ๊ธฐ |
์ฒ์์ ๋ฌธ์ ํ ๋ ์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ก ํ์ด๋ณด๋ผ๋ ๋ง์ ๋ชป๋ณด๊ณ ๋ด ์๋๋ก ํ๋ค๊ฐ ์๊ฐ์ด๊ณผ๊ฐ ๋ฌ๋ค.
์๋์ฝ๋๋ ์๊ฐ์ด๊ณผ ์ฝ๋์ด๋ค.
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer sbf = new StringTokenizer(bfr.readLine(), " ");
int M =Integer.parseInt(sbf.nextToken());
int N =Integer.parseInt(sbf.nextToken());
for(int i = M; i<=N; i++) {
for(int j = 2; j<i; j++) {
if(i%j== 0) break;
if(i==j+1) System.out.println(i);
}
}
}
}
๊ทธ๋์ ์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ฅผ ๊ฒ์ํด๋ณด๋
์์ ์ ์ค๊ณ ๋ฑํ์ ๋ ๋ดค์๋ ์์ ๊ตฌํ๋ ๋ฐฉ๋ฒ์ด ์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ผ๋ ๊ฒ์ด์๋ค. ์ํค๋ฐฑ๊ณผ์ ์ด ๋ฐฉ๋ฒ์ ๊ตฌํํ ์ฝ๋๊ฐ ์์ด์ ์ฝ๋๋ถ์์ ํ๊ณ ์๊ณ ๋ฆฌ์ฆ์ ๊ฐ์ ธ๋ค ์ฌ์ฉํ์๋ค.
import java.util.Scanner;
public class Main {
public static boolean array[];
public static void Eratos() {
array[0] = array[1] = true;
for(int i = 2; i <= Math.sqrt(array.length); i++) { //์ ๊ณฑ๊ทผ
if(array[i] == true) continue;
for(int j = i * i; j < array.length; j += i) {
array[j] = true;
}
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int M = scan.nextInt();
int N = scan.nextInt();
scan.close();
array = new boolean[N+1]; // default = false
Eratos();
for(int i = M; i<=N; i++) {
if(array[i] == false) System.out.println(i);
}
}
}
5 | 4948 | ๋ฒ ๋ฅดํธ๋ ๊ณต์ค |
์ฒ์์๋ ์๋์ ๊ฐ์ด ํ๋๋ฐ ์๊ฐ์ด๊ณผ๊ฐ ๋๊ณ , ์ง์ ์ ์ผ ํฐ ์๋ฅผ ๋ฃ์ด๋ณด๋ ๋์ผ๋ก ํ์ธํ ์ ์์์ ๋์ ์๋๋ก ๋ง์ด ๋๋ ธ๋ค.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (true) {
int n = scan.nextInt();
int count = 0;
if(n == 0) return;
if(n == 1) {
System.out.println(1);
continue;
}
for(int i = n+1; i<=2*n; i++) {
for(int j =2; j<i; j++) {
if(i%j == 0 ) break;
if(j == i-1) count++;
}
}
System.out.println(count);
}
}
}
๊ทธ๋์ ๋ฐ๋ก ์ง์ ์ ๋ฌธ์ ๋ฅผ ๊ฐ์ ธ์์ ์ฝ๋๋ฅผ ๋ค์ ์งฐ๋ค. ํ์คํ ์๋ ์ฐจ์ด๊ฐ ๋๊ปด์ก๋ค.
import java.util.Scanner;
public class Main {
public static boolean array[];
public static void Eratos() {
array[0] = array[1] = true;
for(int i = 2; i <= Math.sqrt(array.length); i++) { //์ ๊ณฑ๊ทผ
if(array[i] == true) continue;
for(int j = i * i; j < array.length; j += i) {
array[j] = true;
}
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(true) {
int N = scan.nextInt();
if(N==0) return;
array = new boolean[2*N+1]; // default = false
Eratos();
int count = 0;
for(int i = N+1; i<=2*N; i++)
if(array[i] == false) count++;
System.out.println(count);
}
}
}
6 | 9020 | ๊ณจ๋๋ฐํ์ ์ถ์ธก |
import java.util.Scanner;
public class Main {
public static boolean array[];
public static void Eratos() {
array[0] = array[1] = true;
for(int i = 2; i <= Math.sqrt(array.length); i++) { //์ ๊ณฑ๊ทผ
if(array[i] == true) continue;
for(int j = i * i; j < array.length; j += i) {
array[j] = true;
}
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int t = 0; t<T; t++) {
int N = scan.nextInt();
array = new boolean[10000]; // default = false
Eratos();
for(int i = 0; i<(N/2); i++) {
if(!array[N/2 - i] && !array[N/2 + i]) {
System.out.println((N/2 -i) + " " + (N/2 +i));
break;
}
}
}
}
}
7 | 1085 | ์ง์ฌ๊ฐํ์์ ํ์ถ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int N[] = new int[4];
for(int i = 0; i<N.length; i++)
N[i] = scan.nextInt();
N[2] -= N[0];
N[3] -= N[1];
int min = N[0];
for(int i=1; i<4; i++)
if(min>N[i])
min = N[i];
System.out.println(min);
}
}
8 | 3009 | ๋ค ๋ฒ์งธ ์ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int ax = scan.nextInt();
int ay = scan.nextInt();
int bx = scan.nextInt();
int by = scan.nextInt();
int cx = scan.nextInt();
int cy = scan.nextInt();
int x = 0 , y = 0;
if(ax == bx) x= cx;
else if(ax == cx) x= bx;
else x= ax;
if(ay == by) y =cy;
else if(ay == cy) y = by;
else y = ay;
System.out.println(x + " " + y);
}
}
9 | 4153 | ์ง๊ฐ์ผ๊ฐํ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(true) {
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
if(a==0 && b==0 &&c==0) return;
int max =0;
if(a>b && a>c)
if(a*a == b*b + c*c) System.out.println("right");
else System.out.println("wrong");
else if(b>a && b>c)
if(b*b == a*a + c*c) System.out.println("right");
else System.out.println("wrong");
else
if(c*c == a*a + b*b) System.out.println("right");
else System.out.println("wrong");
}
}
}
10 | 3053 | ํ์ ๊ธฐํํ |
ํ์ ๊ธฐํํ์ด ๋ฌด์์ด๋.
import java.math.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double R = scan.nextDouble();
scan.close();
System.out.println(R * R * Math.PI);
System.out.println(2 * R * R);
}
}
11 | 1002 | ํฐ๋ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int i = 0; i<T; i++) {
int x1 = scan.nextInt();
int y1 = scan.nextInt();
int r1 = scan.nextInt();
int x2 = scan.nextInt();
int y2 = scan.nextInt();
int r2 = scan.nextInt();
if(x1 == x2 && y1 == y2) {// ๋ ์ ์ ์ขํ๊ฐ ๊ฐ์ผ๋ฉด
if(r1 != r2) {//์ ์ ์์
System.out.println(0);
continue;
}
else { //์ ์ ๋ฌดํ๋
System.out.println(-1);
continue;
}
}
else {
double dis = Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1,2));
if(dis > r1 + r2 || dis <Math.abs(r1-r2)) System.out.println(0);
else if(dis == r1+r2 || dis == Math.abs(r1-r2)) System.out.println(1);
else System.out.println(2);
}
}
scan.close();
}
}