Problem Statement
The International Olympiad in Informatics (IOI) is currently in progress. To honor this competition, our problems for this round have IOI-flavored stories.
Sometimes an IOI task will use a different model of computation in order to bring the contestants out of their comfort zone. For example, in the IOI 2012 task "Odometer" the contestants were programming a simple robot on a grid to solve some algorithmic problems. This problem will also offer you such an experience.
In this problem, a valid program is a finite sequence of positive rational numbers. Let N and D be the sequence of their numerators and the sequence of their denominators, respectively.
The memory of our program consists of a single positive integer M.
When executing a program, each step looks as follows:
- Find the smallest i such that M * (N[i] / D[i]) is an integer.
- If such an i does not exist, the program terminates.
- Otherwise, the new value of M is M * (N[i] / D[i]).
(Note: operations * and / used above are operations on reals. In the implementation of an interpreter we first multiply M by N[i] and then we divide the result by D[i].)
Example:
Consider the program {1/8, 9/4, 3/2}. For this program we have N = {1, 9, 3} and D = {8, 4, 2}.
Whenever we start this program with M = 2x, it will eventually terminate and the value of M at the end of the computation will be 3y where y = x mod 3.
E.g., if we start with M = 210 = 1024, during the computation we will see the values M = 128, M = 16, M = 2, and finally M = 3. At this point the computation stops because none of 3/8, 27/4, and 9/2 is an integer.
Note that the order of fractions matters. E.g., the program {9/4, 3/2, 1/8} converts 2x into 3x instead.
Other programs that also convert 2x into 3x mod 3 include {1/8, 3/2}, {3/2, 1/27}, and {1/27, 3/2}.
------------------------------------------------------------------------
Given five numbers a, b, c, d, e, their median med(a,b,c,d,e) is the value that would be in the middle if we sorted them. For example, med(1,5,2,3,4) = 3, med(1,1,2,2,3) = 2, and med(1,2,7,2,10) = 2.
Your task is to write a program that works as follows:
- It is guaranteed that at the beginning of the program the value M has the form (2a * 3b * 5c * 7d * 11e) for some 0 <= a,b,c,d,e <= 100.
- Let m = med(a,b,c,d,e).
- Your program must eventually terminate, and when it does, the final value M must be equal to 47m.
Your program must satisfy the following additional constraints:
- At most 99 instructions.
- At most 3,000 steps of execution for any valid starting value M.
- Each numerator and denominator must be a positive integer that fits into a signed 32-bit integer variable.
- The value of M must never exceed 10^2500.
As our backend does not support this weird model, your actual task is to write a program in an ordinary programming language that produces the program { N[0] / D[0], N[1] / D[1], ... } and returns the
Your program is given a
Definition
- Class:
- IOIWeirdModel1
- Method:
- program
- Parameters:
- int
- Returns:
- int[]
- Method signature:
- int[] program(int L)
- (be sure your method is public)
Notes
- We recommend (but do not require) that in your program N[i] and D[i] should always be coprime to avoid confusion when thinking about "when is M * N[i] / D[i] an integer?".
- Using N[i] and D[i] that are not coprime is never needed. Clearly, for any positive integer x, a program with N[i] = x*y and D[i] = x*z is equivalent to a program with N[i] = y and D[i] = z.
Constraints
- L will be between 1 and 100, inclusive.
Examples
2
Returns: {2209, 54450, 47, 7623, 1, 7 }
The three tests used for L = 2 are {a,b,c,d,e} = {0,2,0,1,2}, {1,2,2,0,2}, and {0,0,0,1,0}. The example output is a program that solves these three inputs correctly by handling each of them as a separate special case. (This program does not solve all test cases with L=2 correctly, and it fails system tests.)
0
Returns: {47, 2310, 47, 210, 47, 330, 47, 462, 47, 770, 47, 1155, 47, 30, 47, 42, 47, 70, 47, 105, 47, 66, 47, 110, 47, 165, 47, 154, 47, 231, 47, 385, 1, 2, 1, 3, 1, 5, 1, 7, 1, 11 }
1
Returns: {47, 2310, 47, 210, 47, 330, 47, 462, 47, 770, 47, 1155, 47, 30, 47, 42, 47, 70, 47, 105, 47, 66, 47, 110, 47, 165, 47, 154, 47, 231, 47, 385, 1, 2, 1, 3, 1, 5, 1, 7, 1, 11 }
3
Returns: {47, 2310, 47, 210, 47, 330, 47, 462, 47, 770, 47, 1155, 47, 30, 47, 42, 47, 70, 47, 105, 47, 66, 47, 110, 47, 165, 47, 154, 47, 231, 47, 385, 1, 2, 1, 3, 1, 5, 1, 7, 1, 11 }
7
Returns: {47, 2310, 47, 210, 47, 330, 47, 462, 47, 770, 47, 1155, 47, 30, 47, 42, 47, 70, 47, 105, 47, 66, 47, 110, 47, 165, 47, 154, 47, 231, 47, 385, 1, 2, 1, 3, 1, 5, 1, 7, 1, 11 }
99
Returns: {47, 2310, 47, 210, 47, 330, 47, 462, 47, 770, 47, 1155, 47, 30, 47, 42, 47, 70, 47, 105, 47, 66, 47, 110, 47, 165, 47, 154, 47, 231, 47, 385, 1, 2, 1, 3, 1, 5, 1, 7, 1, 11 }
100
Returns: {47, 2310, 47, 210, 47, 330, 47, 462, 47, 770, 47, 1155, 47, 30, 47, 42, 47, 70, 47, 105, 47, 66, 47, 110, 47, 165, 47, 154, 47, 231, 47, 385, 1, 2, 1, 3, 1, 5, 1, 7, 1, 11 }
13
Returns: {47, 2310, 47, 210, 47, 330, 47, 462, 47, 770, 47, 1155, 47, 30, 47, 42, 47, 70, 47, 105, 47, 66, 47, 110, 47, 165, 47, 154, 47, 231, 47, 385, 1, 2, 1, 3, 1, 5, 1, 7, 1, 11 }