Artifact Content
Not logged in

Artifact 275bf68bac25675892fc5444e4a5337b50357f63


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class TheKingsFactorization { public:
	vector<long long> getVector(long long N, vector<long long> primes)
	{
		vector<LL> ans;
		for(int p=2; p<=1000001; ++p)
			while(N%p == 0) {
				ans.push_back(p);
				N /= p;
			}

		// all primes <= cbrt(N) is reported. we have at most 2 more.

		const LL last_p = primes.back();
		if(N%last_p==0 && N!=last_p) {
			ans.push_back(min(N/last_p, last_p));
			ans.push_back(max(N/last_p, last_p));
			N = 1;
		}

		if(N!=1)
			ans.push_back(N);

		return ans;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector<long long>& Expected, const vector<long long>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TheKingsFactorization().getVector(N, primes));}
int main(){

CASE(0)
	long long N = 12LL; 
	long long primes_[] = {2, 3};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	long long __[] = {2, 2, 3 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	long long N = 7LL; 
	long long primes_[] = {7};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	long long __[] = {7 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	long long N = 1764LL; 
	long long primes_[] = {2, 3, 7};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	long long __[] = {2, 2, 3, 3, 7, 7 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	long long N = 49LL; 
	long long primes_[] = {7};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	long long __[] = {7, 7 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	long long N = 210LL; 
	long long primes_[] = {2, 5};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	long long __[] = {2, 3, 5, 7 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	long long N = 100000LL; 
	long long primes_[] = {2, 2, 2, 5, 5};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	long long __[] = {2, 2, 2, 2, 2, 5, 5, 5, 5, 5 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(6)
	long long N = 540000003780LL; 
	long long primes_[] = {2,3,3,1000000007};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	  long long __[] = {2,2,3,3,3,5,1000000007};
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(7)
	long long N = 2700000018900LL; 
	long long primes_[] = {2,3,3,5};
	  vector<long long> primes(primes_, primes_+sizeof(primes_)/sizeof(*primes_)); 
	  long long __[] = {2,2,3,3,3,5,5,1000000007};
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
}
// END CUT HERE