We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan= new Scanner(System.in);
int casos= scan.nextInt();
for (int i = 0; i < casos; i++) {
int number= scan.nextInt();
if(number<=1){
System.out.println("Not prime");
}else{
boolean esPrimo=true;
for (int j = 2; j <= Math.sqrt(number); j++) {
if(number%j==0){
esPrimo=false;
break;
}
}
if(!esPrimo){
System.out.println("Not prime");
}else{
System.out.println("Prime");
}
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
}