Given an integer and an integer that is coprime with . There is a country consisting of islands . For any two different islands and , there is a one-way ferry from to if and only if . A tourist hopes to visit as many islands as possible. He can first fly to any island he chooses to start the tour, and afterwards can only use the one-way ferry to tour freely between islands in this country. Find the maximum possible number of different islands that the tourist can visit.
Problem 1945
Official solution
Let and . Let the maximum number of islands that can be visited be denoted as . Then we have:
For and , if , we denote this as . Let be a prime factor of and . For a sequence , the same relation holds modulo :
(1) If , then is coprime to . This is because , and . Therefore, . Since is coprime to , we have , which implies .
(2) If is coprime to , then . This is because , and since , we have .
(3) From (1) and (2), we can conclude that if , the sequence undergoes at most three changes: it changes from being divisible by to being nonzero, then becomes coprime to , and finally becomes congruent to modulo .
If and , then undergo at most two changes: it changes from being congruent to 0 modulo to being coprime to , and finally becomes congruent to modulo .
If and , then undergo at most one change: it changes from being congruent to 0 modulo 2 to being congruent to modulo 2.
Assuming that have distinct adjacent terms, then adjacent terms have changes in some modulo , implying that .
(4) Construct examples for . First, consider the cases based on modulo .
(i) If , we have .
(ii) If and , we have , where is coprime to and .
(iii) If and , we have .
Let be the prime factorization of . For each , we choose a sequence corresponding to the three cases mentioned above. Note that and . We can appropriately add some zeros at the beginning and some 's at the end of the sequences to ensure that their lengths reach . Let's denote these modified sequences as . It is required that for and (), the positions where changes occur in and are different.
For example, suppose , we can take
If and , we can also take
and continue this way to construct .
By using the -th term of and the Chinese Remainder Theorem, we can determine . Since for , it follows that . Moreover, the sequence modulo has distinct terms. This confirms the conclusion of the original problem, and the maximum value is given by the formula mentioned at the beginning of the solution.