You are viewing a single comment's thread. Return to all comments →
public static String primality(int n) { if(n==1) return "Not prime"; // Write your code here int count =0; for(int i=1;i<=Math.sqrt(n);i++){ if(n%i==0){ count++; } } if(count==1){ return "Prime"; }else{ return "Not prime"; } }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Time Complexity: Primality
You are viewing a single comment's thread. Return to all comments →