The land of Dialectica is ruled over by a large council, with each member being a representative for some constituency of those living within Dialectica. The council makes many important decisions about how the land is managed and governed, and each decision must pass a unanimous vote before it is put into action.
When an issue is raised before the council, every member begins with his or her own opinions on the subject. In order to reach a group consensus, the each member of the council is randomly paired off with another member, and they will debate each other about the topic until one member has convinced the other. Fortunately the people of Dialectica are easily persuaded, and so the first member of the pair to speak will convince the second member, who will listen and adopt the opinions of the first. The process of random pairing then repeats for multiple rounds until all members of the council are in agreement.
Imagine the council members initially seated in a long line. To pair off the members, a debate will occur between seats 1 and 2, between seats 3 and 4, and so forth. After the round is complete, the new seating order of the of the council members will be shuffled using the method we had previously detailed in the Shuffling task (use values a = 445, c = 700001, m = 2097069 for the Linear Congruential Generator), before another round of debate is initiated.
Using a seed value of x0 = 12345 for the Linear Congruential Generator and a council of 10 members, we see that it takes 18 rounds of debates before the council members have reached a consensus.
debates held: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# of opinions: 10 5 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 1
Input Data
First line will be to integers x0 n, with x0 being the seed value of the Linear Congruential Generator and n being the quantity of council members.
Answer
Should consists a single integer, corresponding to how many rounds of debate were required until the council reached consensus.
Example
input data:
10 12345
answer:
18