voidInitPrimeTable(){ for (int i = 2; i <= 10000; ++i) { if (IsNotPrime[i] == false) { PrimeTable.push_back(i); for (int j = i * i; j <= 10000; j += i) { IsNotPrime[j] = true; } } } }
voidInitCandidates(){ for (int i = 0; i < PrimeTable.size(); ++i) { constint& prime = PrimeTable[i]; if (m % (prime - 1) == 0) { Candidates.push_back(prime); } if ((prime - 1) * (prime - 1) > m) { break; } } }
int Ans;
inlineboolJudgt(constint& Remainder){ for (int i = 0; i < PrimeTable.size(); ++i) { constint& prime = PrimeTable[i]; if (Remainder % prime == 0) { returnfalse; } if (prime * prime > Remainder) { break; } }
return Used.find(Remainder) == Used.end(); }
voidDFS(int Index = 0, int Remainder = m, int n = 1){ if (Index == Candidates.size()) { if (Remainder == 1) { Ans = min(Ans, n); } elseif (Judgt(Remainder + 1)) { n *= (Remainder + 1); Ans = min(Ans, n); } return; }