We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>usingnamespacestd;stringltrim(conststring&);stringrtrim(conststring&);/* * 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);intprimeCount(longn){longlongres=0,factors=1;for(auto&x:pri){if(factors*x>n)break;res++;factors*=x;}returnres;}intmain(){ofstreamfout(getenv("OUTPUT_PATH"));stringq_temp;getline(cin,q_temp);intq=stoi(ltrim(rtrim(q_temp)));primes[0]=primes[1]=0;for(intp=2;p*p<=(int)1e4+1;p++){if(!primes[p])continue;pri.push_back(p);for(intj=p*p;j<=(int)1e4+1;j+=p){primes[j]=false;}}for(intq_itr=0;q_itr<q;q_itr++){stringn_temp;getline(cin,n_temp);longn=stol(ltrim(rtrim(n_temp)));intresult=primeCount(n);fout<<result<<"\n";}fout.close();return0;}stringltrim(conststring&str){strings(str);s.erase(s.begin(),find_if(s.begin(),s.end(),not1(ptr_fun<int,int>(isspace))));returns;}stringrtrim(conststring&str){strings(str);s.erase(find_if(s.rbegin(),s.rend(),not1(ptr_fun<int,int>(isspace))).base(),s.end());returns;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Leonardo's Prime Factors
You are viewing a single comment's thread. Return to all comments →
Why my solution gets wa?