-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |