Skip to content

Commit

Permalink
Feat:Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
sa11k committed Jul 12, 2022
1 parent 59b9312 commit a660238
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/BaekJoon/sa11k/1920/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.util.*;
import java.io.*;

public class Main {
static int[] input;

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int inputNum = Integer.parseInt(br.readLine());
input = new int[inputNum];

StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for(int i = 0; i<inputNum; i++){
input[i] = Integer.parseInt(st.nextToken());
}

Arrays.sort(input);

int check = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine(), " ");

for(int i = 0; i<check; i++){
if(search(Integer.parseInt(st.nextToken())) >= 0)
System.out.println(1);
else
System.out.println(0);
}

br.close();
}

public static int search(int num){
int left = 0;
int right = input.length-1;

while(left<=right){
int mid = (left+right) / 2;

if(num < input[mid])
right = mid - 1;

else if(num > input[mid])
left = mid + 1;

else
return mid;
}

return -1;
}
}
34 changes: 34 additions & 0 deletions src/BaekJoon/sa11k/1929/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.*;
import java.io.*;

public class Main {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
StringBuilder sb = new StringBuilder();

int M = Integer.parseInt(st.nextToken());
int N = Integer.parseInt(st.nextToken());

for(int i = M; i<=N; i++){
if(checkPrime(i)){
sb.append(i).append("\n");
}
}

System.out.println(sb);
br.close();
}

public static boolean checkPrime(int num){
if(num<=1) return false;
else if(num==2) return true;
else{
for(int i = 2; i<=Math.sqrt(num); i++){
if((num % i) == 0) return false;
}
return true;
}
}
}

0 comments on commit a660238

Please sign in to comment.