What's wrong with this solution


  • 0
    H

    class Solution {
    public:
    int countPrimes(int n) {

            int total = 0;
    	for (int i = 1; i < n; i++) {
    		if (i % 2 == 0) {
    			total++;
    		}
    	}
    
    	for (int i = 1; i < n; i++) {
    		if ((i % 3 == 0) && (i % 6 != 0)) {
    			total++;
    		}
    	}
    
    	for (int i = 1; i < n; i++) {
    		if ((i % 5 == 0) && (i % 10 != 0) && (i % 15 != 0)) {
    			total++;
    		}
    	}
    
    	for (int i = 1; i < n; i++) {
    		if ((i % 7 == 0) && (i % 14 != 0) && (i % 21 != 0) && (i % 35 != 0)) {
    			total++;
    		}
    	}
            return n + 2 - total ;
    }
    

    };


Log in to reply
 

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