Time Complexity: Primality

  • + 0 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";
        }
        }