# UVa the Cat in the Hat (mathematics)

Source: Internet
Author: User
Tags time limit

107-the Cat in the Hat

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem &problem=43

Background

(an homage to Theodore Seuss Geisel)

The Cat in the ' hat is ' a nasty creature, But the striped Hat is wearing has a rather nifty.

With one flick of the His wrist him pops his.

Do you know what ' s inside that Cat's hat? A Bunch of small cats, each with its own striped hat.

Each little cat does the same as line three, all except the littlest ones, who just say ' Why me? '

Because the littlest cats have to clean all the grime, and they ' re tired of doing it time after time!

The Problem

A clever cat walks into a messy room which him needs to clean. Instead of doing the work alone, it decides to have it helper cats do the work. It keeps its (smaller) helper cats inside its hat. Each helper cat also has helper cats into its own hat, and. Eventually, the cats reach a smallest size. These smallest cats have no. additional cats in their hats. These unfortunate smallest cats have to do the cleaning.

The number of cats inside each (non-smallest) Cat ' s hat is a constant, N. The height of these cats-in-a-hat are times the height of the ' cat whose hat they are in.

the
smallest cats are
of the height one; these are the cats the work is done.

All heights are positive integers.

Given the initial cat and the number of worker cats (of height one), find the number of cats that are does ing any work (cats of height greater than one) and also determine the sum of all cats ' heights ' (the height of a stack Of all cats standing one to top of another).

The Input

The input consists of a sequence of cat-in-hat specifications. Each specification was a single line consisting of the two positive integers, separated by white space. The "the" initial cat, and the second integer is the number of worker cats.

A pair of 0 ' s on a line indicates the end of input.

The Output

For each input line (cat-in-hat specification), print the number of cats this are not working, followed by a space, follow Ed by the height of the stack of cats. There should is one output line for each input line other than the ' 0 0 ' terminates input.

Sample Input

```216
5764801 1679616
0 0```

Sample Output

```671
335923 30275911```

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.