solution of count primes


  • 0
    K

    int countPrimes(int n) {
    if(n<=2)
    return 0;
    else if(n==3)
    return 1;
    else{
    int count=1;
    for(int i=3;i<n;i+=2){
    int c=0;
    for(int j=3;j<=i/2;j++){
    if(i%j==0){
    c=1;
    break;
    }
    }
    if(c==0)
    count++;
    }
    return count;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.