Time Complexity: Primality

  • + 0 comments
    string primality(int n) {
        bool flag = true;
        if(n == 1){
            flag = false;
        }
        for(int i = 2; i <= sqrt(n); ++i){
            if(n % i == 0){
                flag = false;
            }
        }
        return flag ? "Prime" : "Not prime";
    }