Artifact Content
Not logged in

Artifact db25efd7570142d968a9ed879e1e6869515b50a4


#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 <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

LL gcd(LL a, LL b)
{
	while(a)
		swap(a, b%=a);
	return b;
}

class EllysNumbers { public:
	long long getSubsets(long long n, vector <string> special)
	{
		vector<LL> sp; {
			stringstream sin( accumulate(special.begin(), special.end(), string("")) );
			for(LL v; sin>>v; )
				if(n%v==0 && gcd(n/v,v)==1)
					sp.push_back(v);
		}

		map<LL, LL> w;
		w[n] = 1;
		for(int i=0; i<sp.size(); ++i)
			for(map<LL, LL>::iterator it=w.begin(); it!=w.end(); ++it)
				if(it->first%sp[i]==0)
					w[it->first/sp[i]] += it->second;
		return w[1];
	}
};

// 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(_, EllysNumbers().getSubsets(n, special));}
int main(){

CASE(0)
	long long n = 12LL; 
	string special_[] = {"4 2 5 6 3"};
	  vector <string> special(special_, special_+sizeof(special_)/sizeof(*special_)); 
	long long _ = 1LL; 
END
CASE(1)
	long long n = 42LL; 
	string special_[] = {"1 2 3 4 5 6 7 13 14 21 42"};
	  vector <string> special(special_, special_+sizeof(special_)/sizeof(*special_)); 
	long long _ = 10LL; 
END
CASE(2)
	long long n = 1337LL; 
	string special_[] = {"1 13 42 666 2674"};
	  vector <string> special(special_, special_+sizeof(special_)/sizeof(*special_)); 
	long long _ = 0LL; 
END
CASE(3)
	long long n = 1073741824LL; 
	string special_[] = {"1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 1",
 "6384 32768 65536 131072 262144 524288 1048576 2097",
 "152 4194304 8388608 16777216 33554432 67108864 134",
 "217728 268435456 536870912"};
	  vector <string> special(special_, special_+sizeof(special_)/sizeof(*special_)); 
	long long _ = 0LL; 
END
CASE(4)
	long long n = 7420738134810LL; 
	string special_[] = {"435 625199055 4199 33263 17 222870 284870433 72093",
 "2379 7 11 31 247110827 23 1771 81809 851968487 13 ", 
 "476379795 1001 5 435274114 38264554 7429 239906525",
 " 3 227183706 887045414 606786670 3795 797605175 29",
 " 30 747186719 19 2 562347843 74 2294 588002688 743",
 "6429 703 591740547 36657492 37 444178205 1002001 2",
 "17626404"};
	  vector <string> special(special_, special_+sizeof(special_)/sizeof(*special_)); 
	long long _ = 110LL; 
END
CASE(5)
	long long n = 1LL<<45; 
	string special_[] = {"1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384"};
	  vector <string> special(special_, special_+sizeof(special_)/sizeof(*special_)); 
	long long _ = 0LL; 
END
CASE(7)
	long long n = 614889782588491410LL;
	string special_[] = {"2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 6 10 14 2", "2 26 34 38 46 58 62 74 82 86 94 15 21 33 39 51 57 ", "69 87 93 111 123 129 141 35 55 65 85 95 115 145 15", "5 185 205 215 235 77 91 119 133 161 203 217 259 28", "7 301 329 143 187 209 253 319 341 407 451 473 517 ", "221 247 299 377 403 481 533 559 611 323 391 493 52", "7 629 697 731 799 437 551 589 703 779 817 893 667 ", "713 851 943 989 1081 899 1073 1189 1247 1363 1147 ", "1271 1333 1457 1517 1591 1739 1763 1927 2021 11803", " 18377 2337 1479 1886 4945 4199 71299 6235 246 982", "3 4921 8569 14053 16813 31487 17719 1426 2109 258 ", "16967 22607 13243 2001 4495 3059 2553 4403 1598 35", "65 9635 9541 310 2849 5453 6923 3857 1885 645 2303", " 14663 36859 6721 658 2091 1833 1419 32759 68413 3", "995 34891 55883 2233 5945 10199 222 2542 1595 1616", "9 23693 741 7657 2255 3485 43993 4123 40549 26381 ", "2465 41971 5781 29971 387 1551 230 8177 20213 1912", "9 1443 22231 7567 11339 8897 627 638 12617 2737 14", "35 651 14467 20539 987 5217 12673 2193 3367 62651 ", "24679 418 186 12121 5117 1767 4301 238 9889 1798 8", "987 1677 7733 261 2666 13079 16027 1034 1547 3034 ", "17081 8029 2365 465 11687 20683 75 13717 345 561 3", "9997 5423 7429 28681 14147 29233 3619 16211 22591 ", "59737 52111 897 24863 5797 34481 266 1558 374 1061", "9 3895 2139 1702 2639 1394 1421 2635 102 4147 3689", " 8959 429 285 27683 442 2397 18241 4277 6919 325 1", "4993 2783 1066 3451 20387 6601 1118 114 36613 1189", "1 1505 518 42 16687 5957 1462 7337 3741 12259 9331", " 231 3441 273 5819 18491 470 1599 9139 2717 10127 ", "1653 2755 2494 5735 9061 705 874 65231 15181 1771 ", "195 435 130 867 2093 33497 29563 182 33041 4879 66", "5 16523 4371 1023 1222 8729 3731 5593 1311 4715 77", "7 370 935 17917 8041 969 6665 4089 24037 13547 229", "4 6149 322 38657 2697 946 4669 1265 38399 6355 100", "13 24149 814 7163 1105 7285 1634 3478 2405 2795 20", "677 2162 1786 609 31349 4807 10621 188 646 6409 17", "29 9361 25897 385 3553 3157 46139 1978 105 46483 1", "9393 962 11951 30229 53621 30659 3243 42253 615 60", "2 25327 1258 3219 3515 861 13889 595 9367 1054 606", "1 682 78 39527 6293 8695 423 6727 2378 15979 138 5", "289 8323 1015 833 21793 5681 2665 35131 16031 410 ", "1058 5863 1295 2015 1334 2967 27869 15283 6063 123", "41 174 44321 24769 124 1615 33263 53909 56129 1113", "7 1309 154 5291 1887 21607 13583 7667 11063 9503 4", "06 931 754 20 30 4773 28823 3854 110 17329 715 506", " 430 574 153 1085 282 2914 82861 1209 3813 1463 11", "31 2387 2146 10105 4551 5719 7585 1353 3655 3055 1", "221 2035 22103 902"};
	  vector <string> special(special_, special_+sizeof(special_)/sizeof(*special_)); 
	long long _ = 188811356LL; 
END
}
// END CUT HERE