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>#define ull unsigned long longusingnamespacestd;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. */ullgcd(ulla,ullb){while(b){ullt=b;b=a%b;a=t;}returna;}intprimeCount(longn){intcount;ullprod;ullprime;if(n<2)return0;prod=2;count=1;for(prime=3;prod*prime<=n;prime+=2){if(gcd(prod,prime)==1){prod*=prime;count++;}}returncount;}intmain(){ofstreamfout(getenv("OUTPUT_PATH"));stringq_temp;getline(cin,q_temp);intq=stoi(ltrim(rtrim(q_temp)));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 →
Refrence to @ian16