답안 #668693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668693 2022-12-04T13:50:56 Z kinope Toys (CEOI18_toy) C++14
100 / 100
4743 ms 88884 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct st{
	int d, i;
	st(){}
	st(int d) : d(d), i(1) {}
};
void getd(int n, vector<st> &d){
		for(int i = 2; i*i <= n; ++i){
				while(n%i==0){
						if(d.size() && d.back().d == i) ++d.back().i;
						else d.emplace_back(st(i));
						n /= i;
				}
		}
		if(n) d.emplace_back(st(n));
}
int antyp[34] = {2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,
	332640,498960};
unordered_map<int, set<int>> dp;
int main(){
		int n;
		scanf("%d", &n);
		if(n==1){printf("1\n0");return 0;}
		vector<st> d; getd(n, d);
		set<int> s, tmp; s.emplace(1);
		dp[2] = {1};
		dp[4] = {2,3};
		dp[6] = {3,5};
		dp[12] = {4,5,6,11};
		dp[24] = {5,6,7,8,9,12,23};
		dp[36] = {6,7,8,10,11,13,18,35};
		dp[48] = {6,7,8,9,10,12,13,14,17,24,47};
		dp[60] = {8,9,10,12,14,15,16,17,21,30,59};
		dp[120] = {9,10,11,12,13,14,15,16,17,18,20,21,22,24,27,31,32,41,60,119};
		dp[180] = {10,11,12,14,15,16,17,18,19,20,22,23,25,26,27,32,34,39,46,47,61,90,179};
		dp[240] = {10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,28,29,30,32,33,36,42,44,51,61,62,81,120,239};
		dp[360] = {11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,33,34,35,36,37,40,43,44,47,48,51,62,64,75,91,92,121,180,359};
		dp[720] = {12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38,41,42,44,45,46,48,49,50,52,53,54,56,59,61,63,64,65,70,76,80,83,87,92,93,96,122,124,147,181,182,241,360,719};
		dp[840] = {15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,46,47,48,51,56,57,59,60,61,66,69,72,73,74,75,80,88,92,107,108,111,125,142,144,171,211,212,281,420,839};
		dp[1260] = {16,17,18,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,47,48,50,52,53,56,58,67,68,69,70,71,72,74,76,78,79,81,86,89,96,97,102,108,109,110,115,130,134,143,147,185,212,214,255,316,317,421,630,1259};
		dp[1680] = {16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,57,58,60,61,62,64,66,67,68,70,73,74,75,76,77,78,80,81,84,86,87,89,90,92,93,99,102,108,109,110,112,117,119,125,126,132,143,144,145,150,172,176,212,213,216,245,282,284,339,421,422,561,840,1679};
		dp[2520] = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,67,68,69,70,71,72,73,74,75,76,77,79,80,81,82,87,90,92,94,97,98,99,100,101,103,104,105,109,110,111,112,113,116,127,131,132,135,139,144,146,148,156,173,181,186,192,213,214,215,220,256,260,283,287,317,318,321,365,422,424,507,631,632,841,1260,2519};
		dp[5040] = {18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,88,89,91,92,93,94,95,97,98,99,100,101,102,104,105,106,110,111,112,113,114,116,117,118,119,121,123,127,128,130,132,133,134,136,137,140,141,142,144,145,146,147,149,150,151,152,153,155,157,160,164,174,176,177,178,182,187,188,193,196,206,214,215,216,217,218,221,232,247,257,258,259,261,270,284,286,288,296,318,319,320,322,329,341,349,366,372,423,424,425,430,508,512,563,567,632,633,636,725,842,844,1011,1261,1262,1681,2520,5039};
		dp[7560] = {19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,111,112,113,114,115,116,118,119,120,122,123,124,128,129,131,133,134,135,137,139,140,141,142,143,144,146,147,148,149,150,152,155,158,162,166,172,175,176,179,181,183,184,188,189,190,192,194,195,196,199,200,208,211,215,216,217,219,220,222,225,227,244,249,258,260,262,266,277,278,280,283,285,289,296,305,319,320,321,322,323,326,337,367,379,383,384,387,396,424,426,428,436,509,517,546,552,633,634,635,640,760,764,843,847,947,948,951,1085,1262,1264,1515,1891,1892,2521,3780,7559};
		dp[10080] = {19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,122,124,128,129,130,131,132,133,134,135,136,137,138,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,158,159,160,161,164,165,169,173,175,176,177,178,179,181,182,183,184,188,189,192,194,195,197,199,200,202,204,207,210,212,215,216,217,218,219,221,222,223,226,231,233,234,235,239,248,250,254,256,258,259,260,262,263,267,271,280,285,286,287,289,290,292,297,314,319,320,321,323,324,330,342,344,345,346,350,364,367,368,373,386,424,425,426,427,428,431,442,487,499,509,510,513,522,564,566,568,576,633,634,635,637,644,677,685,726,732,843,844,845,850,1012,1016,1123,1127,1262,1263,1266,1445,1682,1684,2019,2521,2522,3361,5040,10079};
		dp[15120] = {20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,161,162,163,164,166,167,168,173,176,177,178,179,180,182,184,185,186,188,189,190,191,193,195,196,197,198,200,201,202,204,207,208,209,210,212,216,217,218,219,220,221,223,224,225,226,228,229,230,232,234,244,245,246,247,249,250,253,256,259,260,261,262,263,265,266,267,268,272,278,279,280,281,282,284,285,286,288,290,292,297,298,301,306,310,320,321,322,323,324,326,327,328,331,332,338,343,347,351,361,368,370,374,379,380,384,385,388,389,397,400,416,425,426,427,429,430,432,437,441,454,465,510,512,514,518,532,547,548,553,565,566,569,585,634,635,636,637,638,641,652,727,739,761,762,765,774,844,846,848,856,948,949,950,952,959,1013,1021,1086,1092,1263,1264,1265,1270,1516,1520,1683,1687,1892,1893,1896,2165,2522,2524,3027,3781,3782,5041,7560,15119};
		dp[20160] = {20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,172,174,176,177,178,179,180,181,182,183,184,185,187,188,189,190,191,193,194,195,196,198,199,200,201,202,203,205,208,209,211,213,215,216,217,218,219,220,221,222,223,224,227,229,232,234,235,236,240,242,244,249,250,251,254,255,256,257,259,260,261,262,263,264,267,268,270,272,273,281,282,284,286,287,288,289,290,291,293,294,295,298,299,302,304,312,315,320,321,322,323,324,325,328,329,330,331,332,333,341,343,344,345,346,347,349,350,351,352,356,365,368,369,372,374,375,377,381,387,394,414,425,426,427,428,429,431,432,433,436,443,455,459,463,466,488,490,491,494,500,510,511,514,515,520,523,542,565,566,567,569,570,572,577,585,594,609,634,635,636,638,639,645,660,678,680,682,686,700,727,728,733,746,844,845,846,847,848,851,862,967,979,1013,1014,1017,1026,1124,1126,1128,1136,1263,1264,1265,1267,1274,1349,1357,1446,1452,1683,1684,1685,1690,2020,2024,2243,2247,2522,2523,2526,2885,3362,3364,4035,5041,5042,6721,10080,20159};
		dp[25200] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,143,144,145,146,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,171,172,173,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,200,201,202,204,206,210,211,212,214,215,216,218,219,220,221,222,223,224,225,226,227,229,230,231,233,234,235,236,238,240,241,242,244,245,246,249,250,251,253,254,259,261,262,263,265,269,274,275,277,278,280,288,290,292,296,298,300,301,309,310,311,315,316,317,318,321,322,323,324,326,327,328,330,333,335,336,341,343,345,350,353,354,356,357,358,359,360,361,363,364,365,368,369,370,374,376,382,385,393,394,409,413,420,421,427,428,429,431,433,434,435,436,440,449,458,459,461,462,464,465,477,478,504,512,516,528,530,531,532,533,534,536,537,538,541,548,552,567,571,575,603,608,610,614,620,636,637,640,641,649,668,705,706,707,709,710,712,717,729,734,753,846,848,850,854,868,907,908,913,926,1015,1031,1054,1055,1056,1057,1058,1061,1072,1207,1219,1265,1266,1269,1278,1404,1406,1408,1416,1578,1579,1580,1582,1589,1685,1693,1806,1812,2103,2104,2105,2110,2524,2528,2803,2807,3152,3153,3156,3605,4202,4204,5043,6301,6302,8401,12600,25199};
		dp[27720] = {27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,133,134,135,136,137,138,139,140,141,142,143,144,145,146,148,149,150,151,152,153,154,155,156,157,158,160,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,185,187,188,191,192,193,194,196,197,199,200,202,203,206,207,208,209,210,213,214,215,219,221,222,223,224,225,228,230,232,233,234,235,236,238,239,240,241,242,243,244,245,246,247,248,250,251,252,254,256,257,261,262,266,267,270,271,275,276,282,283,287,290,293,297,299,306,313,316,318,320,324,326,327,328,331,332,336,337,338,339,340,341,344,345,346,347,349,351,352,358,360,367,371,375,377,391,392,393,394,395,396,398,399,400,401,403,404,406,409,410,412,420,430,432,434,435,442,449,452,453,455,461,464,469,470,471,473,475,476,477,478,482,484,491,501,503,504,507,509,510,517,520,522,549,557,623,627,631,641,642,651,659,668,670,672,674,680,699,700,703,704,712,731,775,776,777,779,780,782,787,801,804,825,851,871,930,932,934,938,952,997,998,1003,1016,1159,1160,1161,1162,1163,1166,1177,1270,1280,1327,1339,1391,1392,1395,1404,1544,1546,1548,1556,1853,1861,1986,1992,2313,2314,2315,2320,2529,2776,2780,3083,3087,3467,3468,3471,3965,4622,4624,5547,6931,6932,9241,13860,27719};
		dp[45360] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,236,237,238,239,240,242,243,244,246,247,248,249,250,251,252,254,255,258,260,261,262,263,264,265,266,267,268,269,270,271,273,274,276,277,278,280,281,282,283,284,285,286,287,288,290,292,293,294,296,297,298,299,300,301,302,303,304,305,308,310,312,313,317,320,322,323,324,325,326,327,328,329,330,331,333,334,335,336,337,338,339,340,341,342,345,348,349,351,352,353,354,357,359,360,363,365,370,372,374,376,380,381,382,384,386,387,388,389,390,391,392,393,394,395,397,398,399,401,402,404,408,409,414,415,416,418,420,421,422,424,425,427,428,429,430,431,432,433,434,436,437,438,439,440,441,443,447,448,451,455,456,457,460,462,467,469,473,484,496,512,514,515,516,520,522,524,526,534,535,548,549,550,551,555,556,557,561,562,567,568,571,574,575,576,578,579,581,582,585,587,588,592,606,622,636,637,638,639,640,641,643,644,645,648,649,654,658,662,664,665,682,700,716,729,733,741,763,764,765,767,769,770,771,772,776,781,785,814,818,819,822,824,825,837,846,848,850,852,858,864,866,892,950,951,952,953,954,956,957,958,961,968,991,1015,1019,1023,1051,1088,1090,1094,1100,1120,1140,1141,1144,1145,1153,1172,1265,1266,1267,1269,1270,1272,1277,1294,1305,1329,1518,1520,1522,1526,1540,1627,1628,1633,1646,1685,1689,1705,1894,1895,1896,1897,1898,1901,1912,2167,2179,2273,2274,2277,2286,2524,2526,2528,2536,2838,2839,2840,2842,2849,3029,3037,3246,3252,3783,3784,3785,3790,4540,4544,5043,5047,5672,5673,5676,6485,7562,7564,9075,11341,11342,15121,22680,45359};
		dp[50400] = {23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,250,251,252,253,254,255,256,258,260,261,262,263,264,265,266,267,268,270,271,274,275,276,278,279,281,282,284,289,290,291,293,294,295,296,297,298,299,301,302,303,304,305,306,310,311,312,313,314,316,317,318,319,322,323,324,325,326,327,328,329,331,334,336,337,338,340,342,343,344,346,348,349,350,351,354,355,356,357,358,359,360,361,362,363,364,365,366,368,369,370,371,372,373,375,377,381,383,384,386,387,390,394,395,396,398,410,412,414,416,420,421,422,424,428,429,430,431,432,433,434,435,436,437,439,440,441,442,443,446,447,448,450,451,458,459,460,461,462,463,465,466,469,470,473,478,479,484,491,492,498,499,503,505,513,514,515,517,521,524,526,529,530,531,532,533,534,535,536,537,538,539,542,544,549,550,553,557,560,568,570,572,576,578,580,583,590,602,604,609,610,611,615,616,617,619,621,622,628,637,638,639,641,642,645,648,650,651,669,681,682,689,697,706,707,708,709,710,711,713,714,715,718,719,724,730,734,735,736,745,754,770,788,809,813,821,847,848,849,851,853,854,855,856,860,861,869,898,908,909,912,914,915,927,954,1016,1020,1032,1055,1056,1057,1058,1059,1061,1062,1063,1066,1073,1096,1127,1131,1135,1163,1208,1210,1214,1220,1240,1266,1267,1270,1271,1279,1298,1405,1406,1407,1409,1410,1412,1417,1434,1449,1473,1579,1580,1581,1583,1584,1590,1605,1686,1688,1690,1694,1708,1807,1808,1813,1826,2023,2039,2104,2105,2106,2107,2108,2111,2122,2407,2419,2525,2526,2529,2538,2804,2806,2808,2816,3153,3154,3155,3157,3164,3365,3373,3606,3612,4203,4204,4205,4210,5044,5048,5603,5607,6302,6303,6306,7205,8402,8404,10083,12601,12602,16801,25200,50399};
		dp[55440] = {28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,220,222,223,224,225,226,227,228,229,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,262,263,265,266,267,268,269,271,272,274,276,277,278,280,281,282,283,284,288,290,291,292,294,296,298,300,302,304,306,307,308,311,314,316,317,318,319,321,322,323,324,325,326,327,328,329,330,332,333,334,337,338,339,340,341,342,343,344,345,346,347,348,350,351,352,353,354,356,358,359,360,361,368,371,372,373,376,378,382,386,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,410,411,412,413,417,420,421,422,426,431,432,433,434,435,436,440,443,445,450,452,453,454,456,460,462,464,465,469,470,471,472,473,474,475,476,477,478,479,481,482,483,485,486,488,489,492,493,496,499,502,504,505,506,508,510,511,512,514,515,518,521,522,523,524,527,528,534,539,547,550,551,558,563,564,573,577,580,593,605,612,624,626,628,631,632,634,636,642,643,646,652,653,657,660,669,670,671,673,675,676,677,681,682,688,700,701,702,704,705,708,711,713,714,716,732,735,742,771,776,777,778,779,780,781,783,784,785,788,789,794,795,802,805,806,808,826,840,852,854,860,862,872,889,893,901,904,931,932,933,935,937,938,939,940,941,944,953,982,998,999,1002,1004,1005,1017,1021,1044,1061,1160,1161,1162,1163,1164,1166,1167,1168,1171,1178,1201,1239,1243,1247,1271,1272,1275,1281,1302,1328,1330,1334,1340,1360,1392,1393,1396,1397,1405,1424,1545,1546,1547,1549,1550,1552,1557,1574,1593,1617,1691,1711,1854,1856,1858,1862,1876,1987,1988,1993,2006,2314,2315,2316,2317,2318,2321,2332,2530,2540,2647,2659,2777,2778,2781,2790,3084,3086,3088,3096,3468,3469,3470,3472,3479,3701,3709,3966,3972,4623,4624,4625,4630,5049,5548,5552,6163,6167,6932,6933,6936,7925,9242,9244,11091,13861,13862,18481,27720,55439};
		dp[83160] = {29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,256,257,258,259,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,284,285,286,287,288,289,290,291,292,293,294,295,297,299,300,301,303,304,305,306,308,309,310,313,314,315,316,318,319,320,321,322,324,326,328,329,330,331,332,333,334,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,353,354,355,356,359,360,362,364,367,368,369,370,373,375,377,379,381,382,389,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,410,411,412,413,414,415,416,417,420,422,423,424,430,432,433,434,436,437,438,439,440,442,444,446,448,451,454,455,456,457,463,466,467,471,472,473,475,476,477,478,479,480,481,483,484,486,487,488,492,493,495,500,503,505,506,507,508,509,511,512,513,517,518,519,521,522,523,524,526,527,537,538,539,551,556,559,562,566,575,576,577,578,580,589,596,599,604,605,606,609,611,615,616,618,624,625,627,629,630,633,637,640,643,644,645,650,653,655,661,663,664,667,670,672,674,676,680,682,684,692,695,701,702,703,704,705,706,707,708,709,710,712,713,714,716,719,722,723,724,732,733,749,752,760,770,774,777,778,779,780,781,782,783,784,788,789,791,797,798,803,806,810,811,815,823,827,853,857,864,873,876,895,932,934,936,937,940,942,944,954,957,958,961,967,968,988,999,1000,1001,1005,1006,1007,1011,1012,1018,1031,1072,1095,1155,1161,1162,1163,1164,1165,1166,1168,1169,1170,1173,1174,1179,1190,1198,1202,1204,1222,1225,1256,1272,1274,1282,1292,1324,1329,1333,1341,1381,1393,1394,1395,1397,1399,1400,1401,1402,1406,1415,1444,1493,1494,1497,1499,1500,1512,1525,1539,1546,1548,1550,1552,1558,1565,1566,1592,1855,1859,1863,1891,1901,1902,1911,1932,1988,1990,1994,2000,2020,2085,2086,2089,2090,2098,2117,2315,2316,2317,2319,2320,2322,2327,2344,2385,2409,2531,2551,2778,2780,2782,2786,2800,2977,2978,2983,2996,3085,3089,3105,3469,3470,3471,3472,3473,3476,3487,3790,3800,3967,3979,4163,4164,4167,4176,4624,4626,4628,4636,5549,5557,5946,5952,6933,6934,6935,6940,7569,8320,8324,9243,9247,10397,10398,10401,11885,13862,13864,16635,20791,20792,27721,41580,83159};
		dp[110880] = {29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,295,296,297,299,300,301,302,303,304,305,307,308,309,310,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,367,369,370,371,372,373,374,376,377,378,379,380,382,383,385,386,387,388,389,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,411,412,413,414,415,416,417,418,419,421,422,423,426,427,428,431,432,433,434,435,436,437,438,440,441,442,444,445,446,451,452,453,454,455,456,457,458,459,461,463,464,465,466,467,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,489,490,491,493,494,497,500,503,504,505,506,507,508,509,510,511,512,513,515,516,517,519,520,522,523,524,525,528,529,531,532,533,535,540,542,544,546,548,550,551,552,554,556,557,559,560,562,564,565,566,572,574,576,578,581,584,586,588,594,596,598,606,613,625,626,627,629,630,631,632,633,634,635,637,638,640,641,642,643,644,645,647,649,653,654,657,658,661,662,664,665,666,670,671,672,673,674,675,676,677,678,682,683,686,687,688,689,690,691,695,700,701,702,703,705,706,707,709,712,714,715,716,717,718,722,727,733,734,736,742,743,746,756,772,777,778,779,780,781,782,783,784,785,786,788,789,790,791,792,793,794,795,796,797,803,804,806,807,809,813,816,818,822,826,827,828,835,841,851,853,854,855,860,861,863,865,872,873,874,884,890,892,894,896,900,902,904,905,912,922,930,932,933,934,935,936,937,938,939,940,941,942,943,944,945,947,950,954,955,964,970,983,999,1000,1001,1003,1004,1005,1006,1009,1010,1018,1019,1022,1026,1032,1042,1045,1062,1067,1075,1079,1091,1100,1116,1133,1137,1153,1159,1161,1162,1163,1164,1165,1166,1167,1168,1169,1172,1174,1179,1180,1187,1202,1217,1240,1242,1244,1248,1249,1250,1252,1262,1272,1273,1276,1282,1283,1303,1320,1329,1330,1331,1335,1336,1337,1341,1342,1346,1348,1361,1393,1394,1395,1397,1398,1401,1402,1404,1406,1407,1425,1455,1464,1515,1546,1547,1548,1549,1550,1551,1553,1554,1555,1558,1559,1564,1575,1594,1598,1600,1610,1618,1652,1692,1694,1702,1712,1744,1769,1773,1781,1821,1855,1856,1857,1859,1861,1862,1863,1864,1868,1877,1906,1988,1989,1992,1994,1995,2007,2029,2034,2069,2315,2316,2317,2318,2319,2321,2322,2323,2326,2333,2356,2471,2475,2479,2507,2531,2532,2541,2562,2648,2650,2654,2660,2680,2778,2779,2782,2783,2791,2810,3085,3086,3087,3089,3090,3092,3097,3114,3177,3201,3371,3391,3469,3470,3471,3473,3474,3480,3495,3702,3704,3706,3710,3724,3967,3968,3973,3986,4624,4625,4626,4627,4628,4631,4642,5050,5060,5287,5299,5549,5550,5553,5562,6164,6166,6168,6176,6933,6934,6935,6937,6944,7397,7405,7926,7932,9243,9244,9245,9250,10089,11092,11096,12323,12327,13862,13863,13866,15845,18482,18484,22179,27721,27722,36961,55440,110879};
		dp[166320] = {30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,298,299,300,301,302,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,360,361,362,363,365,367,368,369,370,371,372,373,374,375,376,377,378,380,381,382,383,384,386,388,389,390,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,421,422,423,424,425,426,428,429,430,431,433,434,435,436,437,438,439,440,441,442,443,444,445,447,448,449,451,452,454,455,456,457,458,460,462,464,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,487,488,489,490,491,493,494,495,496,497,498,501,502,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,522,523,524,525,526,527,528,529,530,532,536,538,539,540,541,542,544,545,547,549,552,553,554,557,558,560,561,562,563,565,566,567,569,572,573,575,576,577,578,579,580,581,582,588,590,593,595,597,599,600,605,606,607,610,611,612,613,614,616,617,618,619,625,626,628,629,630,631,632,633,634,636,638,641,644,645,646,647,648,650,651,652,654,655,656,659,661,662,664,665,668,671,672,673,675,676,677,678,679,681,683,684,685,689,690,693,694,696,697,700,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,720,721,722,723,724,725,728,733,734,736,737,743,744,749,750,753,754,757,761,771,772,773,775,778,779,780,781,782,783,784,785,786,787,789,790,791,792,796,797,798,799,800,802,804,806,807,808,809,810,811,812,814,815,816,818,820,824,825,826,828,829,830,832,836,841,842,846,854,855,856,858,862,864,865,866,868,872,874,876,877,884,891,892,895,896,903,906,907,910,911,931,933,934,935,937,938,939,940,941,942,943,945,946,948,949,950,955,957,958,959,960,962,968,969,970,972,974,984,989,990,1000,1001,1002,1003,1004,1006,1007,1008,1012,1013,1016,1018,1019,1021,1023,1031,1032,1033,1036,1043,1046,1063,1067,1073,1096,1102,1106,1119,1156,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1173,1174,1175,1176,1177,1178,1180,1182,1191,1192,1199,1200,1203,1205,1209,1212,1218,1223,1224,1226,1232,1241,1245,1249,1253,1257,1261,1273,1274,1275,1277,1280,1283,1285,1293,1294,1297,1304,1325,1326,1330,1332,1334,1336,1340,1342,1344,1362,1365,1382,1390,1394,1395,1396,1397,1398,1399,1400,1401,1402,1403,1405,1406,1407,1409,1412,1416,1417,1426,1444,1445,1494,1495,1496,1498,1500,1501,1504,1505,1513,1514,1526,1530,1536,1540,1547,1548,1549,1551,1552,1553,1554,1558,1559,1561,1566,1567,1568,1576,1593,1595,1603,1607,1619,1620,1646,1687,1693,1697,1713,1777,1856,1858,1860,1864,1866,1868,1878,1892,1902,1903,1906,1912,1913,1933,1936,1976,1989,1990,1991,1995,1996,1997,2001,2002,2008,2021,2062,2086,2087,2088,2090,2091,2094,2097,2099,2100,2118,2157,2175,2235,2316,2317,2318,2319,2320,2321,2323,2324,2325,2328,2329,2334,2345,2380,2386,2390,2392,2410,2444,2532,2534,2542,2552,2584,2649,2653,2661,2701,2779,2780,2781,2783,2785,2786,2787,2788,2792,2801,2830,2978,2979,2982,2984,2985,2997,3024,3037,3077,3086,3088,3090,3092,3098,3106,3132,3470,3471,3472,3473,3474,3476,3477,3478,3481,3488,3511,3703,3707,3711,3739,3791,3792,3801,3822,3968,3970,3974,3980,4000,4164,4165,4168,4169,4177,4196,4625,4626,4627,4629,4630,4632,4637,4654,4761,4785,5051,5071,5550,5552,5554,5558,5572,5947,5948,5953,5966,6165,6169,6185,6934,6935,6936,6937,6938,6941,6952,7570,7580,7927,7939,8321,8322,8325,8334,9244,9246,9248,9256,10398,10399,10400,10402,10409,11093,11101,11886,11892,13863,13864,13865,13870,15129,16636,16640,18483,18487,20792,20793,20796,23765,27722,27724,33267,41581,41582,55441,83160,166319};
		dp[221760] = {30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,422,423,424,425,427,428,429,430,431,432,433,434,435,436,437,438,439,441,442,443,444,445,446,447,448,449,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,520,521,523,524,525,526,527,529,530,531,532,533,534,536,537,538,541,542,543,544,545,547,548,549,550,551,552,553,554,555,556,557,558,560,561,562,563,564,565,566,567,568,569,572,573,575,576,577,579,580,582,583,585,587,589,592,594,595,596,597,599,601,602,604,606,607,608,610,613,614,615,619,622,626,627,628,629,630,631,632,633,634,635,636,637,638,639,641,642,643,644,645,646,648,649,650,651,652,654,655,656,658,659,660,662,663,665,666,667,668,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,687,688,689,690,691,692,694,695,696,697,698,701,702,703,704,705,706,707,708,710,711,712,713,714,715,716,717,718,719,721,723,725,726,728,729,730,732,734,735,736,737,738,740,741,743,744,745,747,753,756,757,759,768,769,772,773,774,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,801,803,804,805,807,808,809,810,811,814,817,819,821,823,827,828,829,832,836,842,843,850,852,854,855,856,857,858,861,862,863,864,865,866,871,872,873,874,875,878,885,887,891,892,893,895,896,897,898,899,901,903,904,905,906,907,909,910,913,914,920,923,925,928,931,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,951,952,953,954,955,956,959,964,965,967,971,974,977,980,984,985,989,994,997,1000,1001,1002,1004,1005,1006,1007,1008,1010,1011,1017,1019,1020,1023,1024,1026,1027,1033,1036,1037,1043,1046,1047,1054,1056,1063,1064,1068,1070,1072,1074,1076,1080,1082,1084,1090,1092,1094,1100,1101,1102,1117,1126,1130,1134,1136,1138,1144,1146,1148,1154,1156,1160,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1173,1174,1175,1180,1181,1184,1186,1188,1189,1190,1203,1204,1212,1218,1219,1226,1241,1242,1243,1245,1246,1247,1248,1249,1250,1251,1253,1254,1256,1257,1258,1263,1264,1265,1270,1273,1274,1275,1277,1278,1283,1284,1287,1292,1304,1305,1316,1321,1330,1331,1332,1333,1334,1336,1337,1338,1342,1343,1345,1346,1347,1348,1349,1351,1359,1362,1363,1367,1376,1379,1394,1395,1396,1398,1399,1400,1402,1403,1405,1407,1408,1409,1410,1411,1420,1426,1427,1434,1456,1462,1465,1466,1486,1507,1516,1544,1547,1548,1549,1550,1551,1552,1553,1554,1555,1556,1558,1559,1560,1561,1562,1563,1565,1567,1576,1577,1588,1592,1595,1596,1599,1601,1605,1608,1611,1614,1619,1620,1653,1682,1693,1694,1695,1700,1703,1705,1713,1714,1722,1724,1745,1770,1772,1774,1776,1780,1782,1784,1802,1810,1822,1856,1857,1858,1859,1860,1861,1862,1863,1864,1865,1867,1868,1869,1871,1874,1878,1879,1884,1888,1907,1966,1989,1990,1991,1993,1995,1996,1999,2000,2008,2009,2030,2034,2035,2040,2070,2090,2123,2124,2131,2135,2147,2215,2253,2257,2273,2316,2317,2318,2319,2320,2321,2322,2323,2324,2327,2329,2334,2335,2337,2342,2357,2404,2472,2474,2476,2480,2482,2484,2494,2508,2532,2533,2536,2542,2543,2552,2563,2606,2649,2650,2651,2655,2656,2657,2661,2662,2668,2681,2722,2779,2780,2781,2783,2784,2787,2790,2792,2793,2811,2850,2895,2955,3086,3087,3088,3089,3090,3091,3093,3094,3095,3098,3099,3104,3115,3150,3178,3182,3184,3202,3236,3372,3374,3382,3392,3424,3470,3471,3472,3473,3474,3475,3478,3481,3482,3496,3527,3529,3533,3541,3581,3703,3704,3705,3707,3709,3710,3711,3712,3716,3725,3754,3968,3969,3972,3974,3975,3987,4014,4045,4085,4625,4626,4627,4628,4629,4631,4632,4633,4636,4643,4666,4935,4939,4943,4971,5051,5052,5061,5082,5288,5290,5294,5300,5320,5550,5551,5554,5555,5563,5582,6165,6166,6167,6169,6170,6172,6177,6194,6345,6369,6731,6751,6934,6935,6936,6938,6939,6945,6960,7398,7400,7402,7406,7420,7927,7928,7933,7946,9244,9245,9246,9247,9248,9251,9262,10090,10100,10567,10579,11093,11094,11097,11106,12324,12326,12328,12336,13863,13864,13865,13867,13874,14789,14797,15846,15852,18483,18484,18485,18490,20169,22180,22184,24643,24647,27722,27723,27726,31685,36962,36964,44355,55441,55442,73921,110880,221759};
		dp[277200] = {32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,454,455,456,457,458,459,460,461,462,464,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,499,500,503,505,506,508,509,510,512,513,514,515,516,518,519,521,522,525,526,527,528,529,531,532,533,534,535,536,538,539,540,541,542,543,544,546,547,548,549,550,551,552,553,554,555,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,583,584,585,586,591,592,593,594,595,596,597,601,604,605,607,608,609,610,611,612,613,614,615,616,617,618,620,621,624,625,626,628,630,631,632,635,636,637,638,640,644,646,647,648,650,651,656,657,658,659,660,661,662,664,668,669,670,672,673,674,675,676,677,678,679,680,681,682,683,685,686,687,689,690,692,694,695,697,698,699,700,701,703,704,705,706,708,709,712,713,715,716,717,718,719,720,721,722,724,725,727,729,730,731,733,735,736,737,739,740,741,742,744,745,746,748,749,750,754,757,761,763,765,766,767,769,774,775,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,809,810,812,813,816,817,820,822,828,830,831,832,833,834,836,837,838,839,840,842,843,844,845,846,847,848,849,850,852,854,855,856,857,858,859,860,861,862,864,866,868,869,872,874,876,877,878,880,882,884,890,892,893,896,897,898,901,905,908,909,910,913,917,918,921,923,927,929,933,935,936,937,939,941,942,943,944,945,947,948,949,950,951,952,953,956,957,958,961,966,975,977,978,985,986,992,999,1000,1002,1003,1004,1006,1007,1008,1009,1012,1015,1021,1024,1025,1026,1027,1030,1034,1041,1048,1051,1052,1053,1060,1061,1064,1065,1066,1067,1068,1071,1073,1074,1075,1076,1078,1081,1082,1084,1085,1088,1091,1094,1095,1097,1103,1111,1112,1113,1115,1116,1117,1118,1119,1121,1123,1124,1125,1128,1129,1130,1134,1138,1140,1143,1145,1159,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1181,1182,1183,1184,1186,1187,1190,1193,1196,1198,1205,1206,1215,1216,1217,1222,1225,1229,1235,1237,1243,1247,1251,1259,1263,1268,1274,1275,1276,1277,1279,1281,1285,1288,1289,1306,1307,1312,1315,1316,1332,1334,1336,1338,1340,1344,1346,1348,1350,1354,1356,1358,1364,1369,1390,1393,1396,1397,1400,1401,1404,1409,1412,1413,1414,1416,1418,1424,1426,1428,1429,1434,1436,1437,1455,1466,1478,1485,1498,1528,1549,1550,1551,1553,1554,1555,1556,1557,1558,1559,1561,1562,1564,1565,1566,1571,1573,1578,1584,1585,1586,1588,1589,1590,1592,1596,1597,1598,1599,1600,1602,1613,1619,1620,1621,1629,1660,1661,1662,1663,1664,1666,1667,1668,1672,1673,1676,1678,1679,1681,1692,1693,1695,1703,1706,1715,1718,1733,1735,1749,1757,1816,1822,1826,1843,1858,1860,1862,1866,1870,1874,1876,1880,1898,1922,1932,1933,1934,1935,1936,1937,1938,1939,1940,1941,1943,1944,1945,1946,1947,1948,1950,1952,1961,1962,1973,1991,1992,1995,1996,1997,2001,2004,2010,2015,2016,2049,2067,2113,2114,2115,2118,2120,2123,2125,2133,2134,2144,2165,2210,2212,2214,2216,2220,2222,2224,2230,2242,2262,2318,2319,2320,2321,2322,2323,2324,2325,2326,2327,2329,2330,2331,2333,2336,2340,2341,2350,2369,2428,2484,2485,2486,2488,2490,2491,2494,2495,2503,2504,2530,2534,2538,2544,2574,2585,2628,2651,2659,2663,2675,2743,2781,2782,2785,2789,2794,2797,2798,2813,2817,2821,2833,2870,2897,3088,3090,3092,3096,3098,3100,3110,3124,3162,3163,3166,3168,3172,3173,3193,3236,3309,3310,3311,3315,3316,3317,3321,3322,3328,3341,3382,3472,3473,3474,3476,3477,3480,3483,3485,3486,3504,3543,3615,3675,3705,3713,3721,3769,3856,3857,3858,3859,3860,3861,3863,3864,3865,3868,3869,3874,3885,3920,3970,3974,3976,3994,4028,4212,4214,4222,4232,4264,4409,4413,4421,4461,4627,4628,4629,4631,4633,4634,4635,4636,4640,4649,4678,4958,4959,4962,4964,4965,4977,5004,5053,5093,5552,5556,5568,5592,5780,5781,5782,5783,5784,5786,5787,5788,5791,5798,5821,6167,6171,6175,6203,6311,6312,6321,6342,6608,6610,6614,6620,6640,6936,6937,6940,6941,6949,6968,7705,7706,7707,7709,7710,7712,7717,7734,7929,7953,8411,8431,9246,9248,9250,9254,9268,9907,9908,9913,9926,11095,11111,11554,11555,11556,11557,11558,11561,11572,12610,12620,13207,13219,13865,13866,13869,13878,15404,15406,15408,15416,17328,17329,17330,17332,17339,18485,18493,19806,19812,23103,23104,23105,23110,25209,27724,27728,30803,30807,34652,34653,34656,39605,46202,46204,55443,69301,69302,92401,138600,277199};
		dp[332640] = {31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,539,540,541,542,543,544,545,546,548,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,572,573,574,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,594,595,596,598,599,600,601,602,604,606,607,608,609,610,611,612,613,614,615,617,618,619,620,621,622,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,651,652,653,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,697,698,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,733,734,735,736,737,738,740,742,744,745,747,748,750,751,752,754,755,758,760,762,763,764,770,772,773,774,776,777,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,824,825,826,827,828,829,830,831,832,833,836,837,841,842,843,845,846,847,853,855,856,857,859,860,862,863,865,866,867,869,873,874,875,876,877,878,879,882,883,884,885,886,890,892,893,894,896,897,898,902,904,906,907,908,909,911,912,914,916,918,923,924,928,932,934,935,936,937,938,939,940,941,942,943,944,945,946,947,949,950,951,952,956,957,958,959,960,961,963,964,966,967,969,970,971,972,973,974,975,980,985,987,990,991,994,998,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1017,1019,1020,1021,1022,1024,1025,1026,1027,1028,1032,1033,1034,1037,1042,1044,1046,1047,1048,1049,1064,1066,1068,1069,1073,1074,1075,1076,1077,1081,1089,1093,1097,1098,1102,1103,1105,1107,1113,1116,1118,1120,1121,1128,1135,1139,1152,1154,1155,1156,1157,1158,1159,1161,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,1183,1186,1188,1189,1192,1193,1194,1196,1200,1201,1204,1205,1206,1207,1210,1213,1219,1223,1224,1225,1227,1228,1232,1233,1234,1242,1244,1246,1247,1248,1250,1251,1252,1254,1256,1258,1259,1262,1264,1266,1268,1274,1275,1276,1277,1278,1280,1281,1282,1284,1285,1286,1288,1291,1292,1294,1295,1298,1305,1307,1322,1324,1326,1327,1331,1332,1333,1335,1336,1337,1338,1339,1341,1343,1344,1345,1348,1349,1350,1354,1360,1363,1365,1366,1369,1383,1384,1386,1391,1395,1396,1397,1398,1399,1400,1401,1402,1403,1404,1405,1406,1407,1408,1409,1410,1413,1414,1415,1417,1418,1421,1427,1429,1436,1441,1445,1446,1447,1457,1466,1469,1477,1495,1496,1497,1499,1500,1501,1502,1503,1505,1506,1512,1514,1515,1517,1518,1521,1522,1527,1528,1531,1537,1540,1541,1542,1548,1549,1550,1551,1552,1553,1554,1555,1556,1557,1558,1559,1560,1561,1562,1566,1567,1568,1569,1570,1572,1577,1579,1594,1595,1596,1598,1600,1602,1604,1608,1610,1612,1618,1620,1621,1622,1624,1628,1647,1654,1669,1688,1694,1696,1698,1704,1706,1707,1708,1714,1716,1730,1746,1754,1771,1775,1778,1783,1787,1791,1792,1823,1857,1858,1859,1861,1862,1863,1864,1865,1866,1867,1869,1870,1872,1873,1874,1876,1879,1881,1886,1893,1894,1903,1904,1905,1907,1908,1913,1914,1917,1934,1935,1937,1947,1977,1990,1991,1992,1993,1994,1996,1997,1998,2002,2003,2006,2008,2009,2011,2022,2023,2026,2031,2036,2039,2051,2063,2064,2071,2087,2088,2089,2091,2092,2093,2095,2098,2100,2101,2102,2104,2113,2119,2120,2146,2158,2176,2179,2182,2186,2236,2237,2312,2317,2318,2319,2320,2321,2322,2323,2324,2325,2326,2328,2329,2330,2331,2332,2333,2335,2337,2346,2347,2358,2381,2387,2388,2391,2393,2397,2400,2406,2411,2412,2445,2452,2473,2477,2481,2485,2493,2509,2514,2533,2534,2535,2540,2543,2545,2553,2554,2564,2585,2597,2650,2652,2654,2656,2660,2662,2664,2682,2702,2764,2780,2781,2782,2783,2784,2785,2786,2787,2788,2789,2791,2792,2793,2795,2798,2802,2803,2812,2831,2890,2979,2980,2981,2983,2985,2986,2989,2990,2998,2999,3025,3038,3042,3048,3078,3080,3087,3088,3089,3091,3092,3093,3094,3098,3099,3101,3107,3108,3116,3132,3133,3179,3186,3187,3191,3203,3271,3373,3377,3393,3457,3471,3472,3473,3474,3475,3476,3477,3478,3479,3482,3484,3489,3490,3497,3512,3559,3704,3706,3708,3712,3714,3716,3726,3740,3784,3792,3793,3796,3802,3803,3823,3866,3969,3970,3971,3975,3976,3977,3981,3982,3988,4001,4042,4165,4166,4167,4169,4170,4173,4176,4178,4179,4197,4236,4335,4395,4626,4627,4628,4629,4630,4631,4633,4634,4635,4638,4639,4644,4655,4690,4762,4766,4768,4786,4820,5052,5054,5062,5072,5104,5289,5293,5301,5341,5551,5552,5553,5555,5557,5558,5559,5560,5564,5573,5602,5948,5949,5952,5954,5955,5967,5994,6061,6101,6166,6168,6170,6172,6178,6186,6212,6935,6936,6937,6938,6939,6941,6942,6943,6946,6953,6976,7399,7403,7407,7435,7571,7572,7581,7602,7928,7930,7934,7940,7960,8322,8323,8326,8327,8335,8354,9245,9246,9247,9249,9250,9252,9257,9274,9513,9537,10091,10111,10399,10400,10401,10403,10404,10410,10425,11094,11096,11098,11102,11116,11887,11888,11893,11906,12325,12329,12345,13864,13865,13866,13867,13868,13871,13882,15130,15140,15847,15859,16637,16638,16641,16650,18484,18486,18488,18496,20793,20794,20795,20797,20804,22181,22189,23766,23772,27723,27724,27725,27730,30249,33268,33272,36963,36967,41582,41583,41586,47525,55442,55444,66531,83161,83162,110881,166320,332639};
		dp[498960] = {32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,554,555,556,558,559,560,561,562,563,564,565,566,567,568,569,571,572,573,574,575,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,594,595,597,598,599,601,602,603,604,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,689,690,691,692,693,694,695,696,697,698,699,700,701,702,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,750,751,752,753,754,755,756,757,759,762,763,764,765,768,771,772,773,774,775,777,779,780,781,782,783,784,785,786,787,788,789,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,838,839,840,842,843,844,846,847,848,849,850,852,853,856,857,858,859,860,862,864,865,866,867,868,869,870,873,874,876,878,879,880,881,886,888,889,890,892,893,894,897,898,900,901,902,904,905,906,908,909,910,911,912,913,914,915,917,918,920,921,922,923,924,925,927,928,929,930,932,933,935,936,937,939,940,941,942,943,944,945,946,947,948,949,950,951,952,954,955,956,957,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,975,976,977,978,980,981,982,984,985,986,988,990,991,992,993,998,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1020,1021,1023,1025,1029,1031,1032,1033,1034,1035,1036,1037,1038,1041,1045,1048,1052,1053,1054,1055,1058,1059,1060,1061,1065,1066,1069,1075,1077,1078,1085,1093,1098,1100,1104,1106,1108,1109,1110,1116,1117,1118,1120,1121,1124,1130,1136,1150,1151,1154,1155,1158,1160,1161,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,1183,1184,1185,1186,1188,1190,1191,1193,1194,1195,1200,1201,1202,1203,1205,1207,1208,1209,1210,1211,1213,1214,1215,1217,1220,1223,1224,1225,1226,1227,1228,1229,1230,1232,1233,1234,1237,1241,1243,1244,1245,1247,1251,1252,1255,1259,1261,1263,1264,1271,1274,1275,1276,1277,1279,1280,1282,1283,1285,1287,1289,1293,1294,1295,1296,1297,1299,1302,1304,1306,1310,1315,1327,1328,1329,1332,1334,1336,1338,1339,1342,1344,1346,1348,1352,1353,1355,1356,1358,1359,1360,1364,1367,1368,1370,1375,1378,1384,1386,1392,1396,1397,1398,1399,1400,1401,1402,1403,1404,1405,1406,1407,1408,1409,1411,1412,1413,1414,1416,1418,1419,1420,1421,1422,1424,1425,1428,1429,1432,1433,1436,1445,1446,1447,1449,1457,1460,1462,1471,1476,1477,1492,1496,1497,1498,1499,1500,1501,1502,1503,1504,1505,1506,1507,1508,1509,1510,1512,1514,1515,1516,1517,1519,1520,1522,1528,1529,1530,1532,1536,1537,1538,1540,1542,1544,1546,1548,1549,1550,1551,1552,1553,1554,1555,1556,1557,1558,1560,1561,1563,1565,1568,1569,1570,1571,1572,1573,1576,1578,1580,1582,1585,1595,1597,1601,1605,1606,1609,1617,1621,1622,1625,1633,1635,1637,1638,1643,1647,1648,1649,1652,1653,1654,1656,1668,1676,1679,1689,1695,1696,1697,1698,1699,1701,1715,1719,1744,1773,1779,1794,1795,1798,1799,1800,1801,1804,1807,1813,1817,1818,1819,1822,1826,1840,1852,1853,1858,1860,1862,1864,1866,1868,1870,1878,1880,1882,1884,1894,1896,1897,1904,1905,1906,1907,1908,1911,1914,1915,1916,1921,1922,1924,1925,1926,1928,1935,1937,1938,1956,1957,1975,1978,1982,1991,1992,1993,1995,1996,1997,1998,1999,2001,2003,2004,2005,2009,2010,2014,2020,2021,2023,2025,2043,2044,2060,2064,2088,2089,2090,2091,2092,2093,2094,2095,2096,2097,2098,2099,2100,2101,2102,2103,2105,2106,2107,2108,2110,2111,2114,2116,2120,2122,2129,2139,2140,2152,2159,2177,2189,2197,2198,2230,2237,2283,2284,2287,2293,2296,2297,2314,2317,2318,2319,2320,2321,2322,2323,2324,2325,2326,2327,2329,2330,2331,2332,2336,2337,2338,2339,2340,2342,2347,2349,2364,2365,2377,2382,2388,2389,2390,2392,2394,2396,2400,2402,2404,2410,2412,2414,2417,2420,2446,2480,2486,2524,2534,2536,2538,2544,2546,2548,2554,2556,2584,2586,2618,2651,2655,2663,2667,2671,2703,2716,2781,2782,2783,2785,2786,2787,2788,2789,2790,2791,2793,2794,2796,2797,2798,2803,2805,2810,2817,2818,2827,2832,2848,2849,2850,2852,2858,2859,2861,2862,2879,2880,2922,2950,2980,2981,2982,2983,2984,2986,2987,2988,2992,2993,2996,2998,2999,3001,3009,3012,3013,3026,3039,3047,3053,3059,3079,3088,3090,3092,3094,3096,3100,3104,3108,3110,3134,3136,3160,3187,3240,3256,3262,3266,3316,3392,3472,3473,3474,3475,3476,3477,3478,3479,3480,3481,3483,3484,3485,3486,3487,3488,3490,3492,3501,3502,3513,3536,3575,3576,3579,3581,3585,3588,3594,3599,3600,3607,3633,3702,3705,3709,3713,3717,3725,3741,3793,3794,3795,3800,3803,3805,3813,3814,3824,3829,3845,3910,3970,3972,3974,3976,3980,3982,3984,4002,4022,4084,4166,4167,4168,4169,4170,4171,4172,4173,4174,4175,4177,4178,4179,4181,4184,4188,4189,4198,4217,4276,4464,4465,4466,4468,4470,4471,4474,4475,4483,4484,4510,4550,4554,4560,4565,4590,4627,4628,4629,4631,4632,4633,4634,4638,4639,4641,4644,4647,4648,4656,4673,4726,4763,4771,4775,4787,4855,5053,5057,5073,5137,5552,5554,5556,5560,5562,5564,5574,5588,5632,5682,5683,5686,5692,5693,5713,5756,5949,5950,5951,5955,5956,5957,5961,5962,5968,5981,6022,6167,6171,6175,6187,6239,6244,6245,6246,6248,6249,6252,6255,6257,6258,6276,6315,6495,6555,6936,6937,6938,6939,6940,6941,6943,6944,6945,6948,6949,6954,6965,7000,7138,7142,7144,7162,7196,7572,7574,7582,7592,7624,7929,7933,7941,7981,8323,8324,8325,8327,8329,8330,8331,8332,8336,8345,8374,8918,8919,8922,8924,8925,8937,8964,9085,9125,9246,9248,9250,9252,9258,9266,9292,10400,10401,10402,10403,10404,10406,10407,10408,10411,10418,10441,11095,11099,11103,11131,11351,11352,11361,11382,11888,11890,11894,11900,11920,12480,12481,12484,12485,12493,12512,13865,13866,13867,13869,13870,13872,13877,13894,14265,14289,15131,15151,16638,16640,16642,16646,16660,17827,17828,17833,17846,18485,18489,18505,20794,20795,20796,20797,20798,20801,20812,22690,22700,23767,23779,24953,24954,24957,24966,27724,27726,27728,27736,31188,31189,31190,31192,31199,33269,33277,35646,35652,41583,41584,41585,41590,45369,49900,49904,55443,55447,62372,62373,62376,71285,83162,83164,99795,124741,124742,166321,249480,498959};
		for(st dz : d){
				for(int i : s){
						int w = 1;
						for(int c = 1; c <= dz.i; ++c) w *= dz.d, tmp.emplace(i*w);
						tmp.emplace(i);
				}
				s = tmp; tmp.clear();
		} vector<int> D; for(int i : s) if(i!=1) D.emplace_back(i);
		unordered_map<ll, bool> czy, czyantyp; for(int i : D){czy[i] = 1;} for(int i : antyp) czyantyp[i] = 1;
		for(int i : D) if(!czyantyp[i]) dp[i].emplace(i-1);
		
		for(int i = 0; i < (int) D.size(); ++i){
				int a = D[i];
				for(int j = 0; j < (int) D.size(); ++j){
						int b = D[j];
						if(czyantyp[(ll) a * b] || !czy[(ll) a * b]) continue;
						for(int w : dp[a]) dp[a*b].emplace(w+b-1);
				}
		}
		
		printf("%d\n", (int) dp[n].size());
		for(int i : dp[n]) printf("%d ", i);
		/*vector<int> v;
		printf("dp[%d] = {", n);
		for(int i : dp[n]) v.emplace_back(i);
		for(int i = 0; i < (int) v.size()-1; ++i) printf("%d,", v[i]);
		printf("%d};\n", v.back());*/
		return 0;
}

Compilation message

toy.cpp: In function 'int main()':
toy.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 2 ms 892 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 2 ms 852 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 2 ms 892 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 2 ms 852 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 980 KB Output is correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 2 ms 852 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 3 ms 852 KB Output is correct
31 Correct 2 ms 980 KB Output is correct
32 Correct 4 ms 1108 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 2 ms 828 KB Output is correct
35 Correct 1 ms 800 KB Output is correct
36 Correct 2 ms 852 KB Output is correct
37 Correct 2 ms 980 KB Output is correct
38 Correct 2 ms 852 KB Output is correct
39 Correct 2 ms 852 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 1 ms 852 KB Output is correct
43 Correct 1 ms 852 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 852 KB Output is correct
47 Correct 2 ms 1104 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 1 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 2 ms 892 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 2 ms 852 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 980 KB Output is correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 2 ms 852 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 3 ms 852 KB Output is correct
31 Correct 2 ms 980 KB Output is correct
32 Correct 4 ms 1108 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 2 ms 828 KB Output is correct
35 Correct 1 ms 800 KB Output is correct
36 Correct 2 ms 852 KB Output is correct
37 Correct 2 ms 980 KB Output is correct
38 Correct 2 ms 852 KB Output is correct
39 Correct 2 ms 852 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 1 ms 852 KB Output is correct
43 Correct 1 ms 852 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 852 KB Output is correct
47 Correct 2 ms 1104 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 1 ms 852 KB Output is correct
50 Correct 4 ms 1236 KB Output is correct
51 Correct 4 ms 1108 KB Output is correct
52 Correct 3 ms 1108 KB Output is correct
53 Correct 3 ms 1108 KB Output is correct
54 Correct 3 ms 1108 KB Output is correct
55 Correct 6 ms 1288 KB Output is correct
56 Correct 5 ms 1236 KB Output is correct
57 Correct 5 ms 1236 KB Output is correct
58 Correct 1 ms 852 KB Output is correct
59 Correct 2 ms 852 KB Output is correct
60 Correct 2 ms 852 KB Output is correct
61 Correct 4 ms 1108 KB Output is correct
62 Correct 3 ms 980 KB Output is correct
63 Correct 2 ms 980 KB Output is correct
64 Correct 2 ms 852 KB Output is correct
65 Correct 4 ms 1108 KB Output is correct
66 Correct 2 ms 852 KB Output is correct
67 Correct 2 ms 852 KB Output is correct
68 Correct 2 ms 852 KB Output is correct
69 Correct 2 ms 980 KB Output is correct
70 Correct 3 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 2 ms 892 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 2 ms 852 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 980 KB Output is correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 2 ms 852 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 3 ms 852 KB Output is correct
31 Correct 2 ms 980 KB Output is correct
32 Correct 4 ms 1108 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 2 ms 828 KB Output is correct
35 Correct 1 ms 800 KB Output is correct
36 Correct 2 ms 852 KB Output is correct
37 Correct 2 ms 980 KB Output is correct
38 Correct 2 ms 852 KB Output is correct
39 Correct 2 ms 852 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 1 ms 852 KB Output is correct
43 Correct 1 ms 852 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 852 KB Output is correct
47 Correct 2 ms 1104 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 1 ms 852 KB Output is correct
50 Correct 4 ms 1236 KB Output is correct
51 Correct 4 ms 1108 KB Output is correct
52 Correct 3 ms 1108 KB Output is correct
53 Correct 3 ms 1108 KB Output is correct
54 Correct 3 ms 1108 KB Output is correct
55 Correct 6 ms 1288 KB Output is correct
56 Correct 5 ms 1236 KB Output is correct
57 Correct 5 ms 1236 KB Output is correct
58 Correct 1 ms 852 KB Output is correct
59 Correct 2 ms 852 KB Output is correct
60 Correct 2 ms 852 KB Output is correct
61 Correct 4 ms 1108 KB Output is correct
62 Correct 3 ms 980 KB Output is correct
63 Correct 2 ms 980 KB Output is correct
64 Correct 2 ms 852 KB Output is correct
65 Correct 4 ms 1108 KB Output is correct
66 Correct 2 ms 852 KB Output is correct
67 Correct 2 ms 852 KB Output is correct
68 Correct 2 ms 852 KB Output is correct
69 Correct 2 ms 980 KB Output is correct
70 Correct 3 ms 1108 KB Output is correct
71 Correct 598 ms 20228 KB Output is correct
72 Correct 458 ms 15980 KB Output is correct
73 Correct 536 ms 17704 KB Output is correct
74 Correct 279 ms 12792 KB Output is correct
75 Correct 342 ms 13028 KB Output is correct
76 Correct 955 ms 26352 KB Output is correct
77 Correct 806 ms 22604 KB Output is correct
78 Correct 743 ms 21868 KB Output is correct
79 Correct 712 ms 21264 KB Output is correct
80 Correct 2 ms 852 KB Output is correct
81 Correct 2 ms 852 KB Output is correct
82 Correct 5 ms 1236 KB Output is correct
83 Correct 68 ms 4232 KB Output is correct
84 Correct 95 ms 5196 KB Output is correct
85 Correct 15 ms 2132 KB Output is correct
86 Correct 2 ms 980 KB Output is correct
87 Correct 88 ms 5672 KB Output is correct
88 Correct 2 ms 852 KB Output is correct
89 Correct 1 ms 852 KB Output is correct
90 Correct 2 ms 980 KB Output is correct
91 Correct 24 ms 3020 KB Output is correct
92 Correct 142 ms 8648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 2 ms 852 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 2 ms 892 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 2 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 2 ms 852 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 980 KB Output is correct
27 Correct 2 ms 980 KB Output is correct
28 Correct 2 ms 852 KB Output is correct
29 Correct 2 ms 852 KB Output is correct
30 Correct 3 ms 852 KB Output is correct
31 Correct 2 ms 980 KB Output is correct
32 Correct 4 ms 1108 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 2 ms 828 KB Output is correct
35 Correct 1 ms 800 KB Output is correct
36 Correct 2 ms 852 KB Output is correct
37 Correct 2 ms 980 KB Output is correct
38 Correct 2 ms 852 KB Output is correct
39 Correct 2 ms 852 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 1 ms 852 KB Output is correct
43 Correct 1 ms 852 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 852 KB Output is correct
47 Correct 2 ms 1104 KB Output is correct
48 Correct 2 ms 852 KB Output is correct
49 Correct 1 ms 852 KB Output is correct
50 Correct 4 ms 1236 KB Output is correct
51 Correct 4 ms 1108 KB Output is correct
52 Correct 3 ms 1108 KB Output is correct
53 Correct 3 ms 1108 KB Output is correct
54 Correct 3 ms 1108 KB Output is correct
55 Correct 6 ms 1288 KB Output is correct
56 Correct 5 ms 1236 KB Output is correct
57 Correct 5 ms 1236 KB Output is correct
58 Correct 1 ms 852 KB Output is correct
59 Correct 2 ms 852 KB Output is correct
60 Correct 2 ms 852 KB Output is correct
61 Correct 4 ms 1108 KB Output is correct
62 Correct 3 ms 980 KB Output is correct
63 Correct 2 ms 980 KB Output is correct
64 Correct 2 ms 852 KB Output is correct
65 Correct 4 ms 1108 KB Output is correct
66 Correct 2 ms 852 KB Output is correct
67 Correct 2 ms 852 KB Output is correct
68 Correct 2 ms 852 KB Output is correct
69 Correct 2 ms 980 KB Output is correct
70 Correct 3 ms 1108 KB Output is correct
71 Correct 598 ms 20228 KB Output is correct
72 Correct 458 ms 15980 KB Output is correct
73 Correct 536 ms 17704 KB Output is correct
74 Correct 279 ms 12792 KB Output is correct
75 Correct 342 ms 13028 KB Output is correct
76 Correct 955 ms 26352 KB Output is correct
77 Correct 806 ms 22604 KB Output is correct
78 Correct 743 ms 21868 KB Output is correct
79 Correct 712 ms 21264 KB Output is correct
80 Correct 2 ms 852 KB Output is correct
81 Correct 2 ms 852 KB Output is correct
82 Correct 5 ms 1236 KB Output is correct
83 Correct 68 ms 4232 KB Output is correct
84 Correct 95 ms 5196 KB Output is correct
85 Correct 15 ms 2132 KB Output is correct
86 Correct 2 ms 980 KB Output is correct
87 Correct 88 ms 5672 KB Output is correct
88 Correct 2 ms 852 KB Output is correct
89 Correct 1 ms 852 KB Output is correct
90 Correct 2 ms 980 KB Output is correct
91 Correct 24 ms 3020 KB Output is correct
92 Correct 142 ms 8648 KB Output is correct
93 Correct 4238 ms 80524 KB Output is correct
94 Correct 2339 ms 56756 KB Output is correct
95 Correct 2656 ms 57596 KB Output is correct
96 Correct 2252 ms 51632 KB Output is correct
97 Correct 2025 ms 47232 KB Output is correct
98 Correct 4493 ms 88148 KB Output is correct
99 Correct 4743 ms 88884 KB Output is correct
100 Correct 4564 ms 86160 KB Output is correct
101 Correct 3963 ms 78660 KB Output is correct
102 Correct 3513 ms 70880 KB Output is correct
103 Correct 2925 ms 64836 KB Output is correct
104 Correct 2 ms 852 KB Output is correct
105 Correct 2 ms 852 KB Output is correct
106 Correct 8 ms 1492 KB Output is correct
107 Correct 208 ms 10180 KB Output is correct
108 Correct 637 ms 21084 KB Output is correct
109 Correct 42 ms 3812 KB Output is correct
110 Correct 2 ms 852 KB Output is correct
111 Correct 255 ms 12844 KB Output is correct
112 Correct 2 ms 852 KB Output is correct
113 Correct 2 ms 852 KB Output is correct
114 Correct 9 ms 1756 KB Output is correct
115 Correct 2 ms 852 KB Output is correct
116 Correct 16 ms 2444 KB Output is correct
117 Correct 851 ms 29360 KB Output is correct