Artifact 8c5bdf5260c7702442fe6f343523ddcfb4cda739
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
class StrongPrimePower
{
public:
vector <int> baseAndExponent(string n)
{
LL N;
stringstream(n) >> N;
LL sN = (LL) sqrt( (double)N );
if( sN*sN == N && isPrime(sN) ) {
vector<int> ans;
ans.push_back(sN);
ans.push_back(2);
return ans;
}
if( (sN+1)*(sN+1) == N && isPrime(sN+1) ) {
vector<int> ans;
ans.push_back(sN+1);
ans.push_back(2);
return ans;
}
for(LL p=2; p*p*p<=N; ++p)
if( N%p==0 ) {
LL q=0;
while(N%p==0)
N /= p, ++q;
if( N==1 ) {
vector<int> ans;
ans.push_back(p);
ans.push_back(q);
return ans;
}
break;
}
return vector<int>();
}
bool isPrime(LL N) {
for(LL p=2; p*p<=N; ++p)
if(N%p==0)
return false;
return true;
}
};
// BEGIN CUT HERE
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const vector <int> &Expected, const vector <int> &Received) { if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } return 0;}
template<int N> struct Case_ {};
char Test_(...);
int Test_(Case_<0>) {
string n = "27";
int RetVal_[] = {3, 3 };
vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
return verify_case(RetVal, StrongPrimePower().baseAndExponent(n)); }
int Test_(Case_<1>) {
string n = "10";
vector <int> RetVal;
return verify_case(RetVal, StrongPrimePower().baseAndExponent(n)); }
int Test_(Case_<2>) {
string n = "7";
vector <int> RetVal;
return verify_case(RetVal, StrongPrimePower().baseAndExponent(n)); }
int Test_(Case_<3>) {
string n = "1296";
vector <int> RetVal;
return verify_case(RetVal, StrongPrimePower().baseAndExponent(n)); }
int Test_(Case_<4>) {
string n = "576460752303423488";
int RetVal_[] = {2, 59 };
vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
return verify_case(RetVal, StrongPrimePower().baseAndExponent(n)); }
int Test_(Case_<5>) {
string n = "999999874000003969";
int RetVal_[] = {999999937, 2 };
vector <int> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
return verify_case(RetVal, StrongPrimePower().baseAndExponent(n)); }
template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<> void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE