31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9186. Amusement Park. Two carousels(roundabouts) A and B are spinningcontrariwise (see picture 186.1).They have a and b trucks respectively.It is not possible to move from onetruck to another in the same carousel.But carousels are set so close to eachother that one can easily jump from onecarousel into another in the placewhere they adjoin.Picture 185.1At each moment of time one and only one truck of carousel A adjoins with one andonly one truck carousel B. Carousels spin at such speeds that after one moment of timetrucks, neighboring to the trucks that were adjoined at the previous moment, adjoin.At the picture below two black trucks adjoin. After one moment of time two graytrucks will adjoin. For example, someone entered carousel A. He can jump to a truckof carousel B and after carousel B turns around, He can come back to some truck ofthe carousel A.Task. 1) Given the numbers of trucks in both carousels a and b (20 ≤ a, b ≤ maxlongint).At the initial moment the naughty teenager is in the truck of carousel A. The task isto find the number of different trucks of carousel A that the teenager can visit withthe help of carousel B.2) It is known the number of trucks a of the carousel A. The task is to find theminimal number of trucks of carousel B such that the teenager from any truck ofcarousel A could get into any other truck of carousel A with the help of carousel B.Write a single program that could find both numbers (i.e. would solve the firstand the second parts of task).Input. The first line of the input file containsthe number of trucks a of carousel A andthe number of trucks b of carousel B.Number a is the input data to the both partsof the task, and number b is the input data tothe first part only.Picture 186.1InputExampleOutput24 22 1223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!