Artifact Content
Not logged in

Artifact 1bc022689a616900c2ae8ad4c86d3765df135c5d


#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 Procrastination { public:
	long long findFinalAssignee(long long n)
	{
		map<LL, set<LL>> divs;

		for(LL k=2; k*2<=n; ) {
			if(n%k==0) ++n;
			else if(n%k==1) --n;

			set<LL>& dn = divs[n];
			if(dn.empty())
				for(LL p=1; p*p<=n; ++p)
					if(n%p==0) {
						dn.insert(p);
						dn.insert(n/p);
					}
					else if((n-1)%p==0) {
						dn.insert(p);
						dn.insert((n-1)/p);
					}

			k = *dn.lower_bound(k+1);
		}
		return n;
	}
};

// 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 long long& Expected, const 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(_, Procrastination().findFinalAssignee(n));}
int main(){

CASE(0)
	long long n = 3LL; 
	long long _ = 3LL; 
END
CASE(1)
	long long n = 8LL; 
	long long _ = 11LL; 
END
CASE(2)
	long long n = 20LL; 
	long long _ = 20LL; 
END
CASE(3)
	long long n = 196248LL; 
	long long _ = 196259LL; 
END
CASE(4)
	long long n = 5587021440LL; 
	long long _ = 5587021440LL; 
END
/*
CASE(5)
	long long n = LL; 
	long long _ = LL; 
END
CASE(6)
	long long n = LL; 
	long long _ = LL; 
END
*/
}
// END CUT HERE