-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI094.java
More file actions
34 lines (32 loc) · 1.01 KB
/
I094.java
File metadata and controls
34 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package levelB;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class I094 {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] str=br.readLine().split(" ");
String c=br.readLine();
int L=Integer.parseInt(str[0]);
int K=Integer.parseInt(str[1]);
for(int i=0;i<=L-K;i++){
int num=Integer.parseInt(c.substring(i,i+K));
if(isPrime(num)){
System.out.print(c.substring(i,i+K));
return;
}
}
System.out.print("404");
}
public static boolean isPrime(int num){
if(num==1)
return false;
if(num==2||num==3)
return true;
if(num%6!=1&&num%6!=5)
return false;
for(int i=5;i<=Math.sqrt(num);i+=6)
if(num%i==0||num%(i+2)==0)
return false;
return true;
}
}