• + 0 comments

    Why my solution gets wa?

    #include <bits/stdc++.h>
    
    using namespace std;
    
    string ltrim(const string &);
    string rtrim(const string &);
    
    /*
     * Complete the 'primeCount' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts LONG_INTEGER n as parameter.
     */
    vector<long> pri;
    vector<int> primes(1e4+1, true);
    
    int primeCount(long n) {
        
        
        long long res = 0, factors = 1;
        for (auto &x : pri) {
            if (factors * x > n) break;
            res++;
            factors *= x;
        }
        return res;
    }
    
    int main()
    {
        ofstream fout(getenv("OUTPUT_PATH"));
    
        string q_temp;
        getline(cin, q_temp);
    
        int q = stoi(ltrim(rtrim(q_temp)));
        primes[0] = primes[1] = 0;
        for (int p = 2; p*p <= (int)1e4+1; p++) {
            if (!primes[p]) continue;
            pri.push_back(p);
            for (int j = p*p; j <= (int)1e4+1; j+=p) {
                primes[j] = false;
            }
        }
    
        for (int q_itr = 0; q_itr < q; q_itr++) {
            string n_temp;
            getline(cin, n_temp);
    
            long n = stol(ltrim(rtrim(n_temp)));
    
            int result = primeCount(n);
    
            fout << result << "\n";
        }
    
        fout.close();
    
        return 0;
    }
    
    string ltrim(const string &str) {
        string s(str);
    
        s.erase(
            s.begin(),
            find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
        );
    
        return s;
    }
    
    string rtrim(const string &str) {
        string s(str);
    
        s.erase(
            find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
            s.end()
        );
    
        return s;
    }