The Cat in the Hat#1157

The Cat in the Hat

1 секунда
64 мегабајти
Средно

(An homage to Theodor Seuss Geisel)

The Cat in the Hat is a mischievous creature, but the striped hat he wears has a rather remarkable feature. With a flick of his wrist, he pops off the hat. Do you know what's inside that Cat's hat? A gathering of smaller cats, each with its own striped hat. Each little cat does the same as described above, except for the very smallest ones, who just say "Why me?" because the smallest cats have to do all the cleaning, and they are tired of it!

A clever cat must clean a messy room. Instead of doing the task himself, he wants his helper cats to do the work. His (smaller) helpers are inside his hat. Each helper cat also has its own helpers inside its hat, and so on. Eventually, there are the smallest cats who have no helpers; these are the ones that actually do the cleaning.

The number of cats inside each (non-smallest) cat's hat is a constant . The height of a cat in a hat is 1/(N+1) times the height of the cat whose hat it is in.

The smallest cats have height ; these are the cats that do the work. All heights are positive integers.

Given the height of the initial cat and the number of working cats (of height one), determine the number of non-working cats (cats with height greater than one), and also find the sum of the heights of all cats (the height of the stack formed by all the cats standing on top of each other).

Влез

The input consists of a sequence of specifications, each describing a cat in a hat. Each line contains two positive integers separated by a space: the first integer is the height of the initial cat, and the second is the number of working cats. All input values are integers not exceeding 10^9.

A line containing a pair of zeros indicates the end of the input and should not be processed.

Излез

For each input line (cat-in-hat specification), output in a separate line the number of non-working cats and the height of the pyramid made from all the cats, separated by a space.

Примери

Пример 1

Loading
Loading