The Cat in the Hat ultraviolet 107

Source: Internet
Author: User

It's hard to understand this question at the beginning, and it's hard to figure out what to do. In fact, there is a cat, and the height is the input init. There are n cats in its hats. The height of each cat is one of the n + 1 points of init. Then there are also n cats in the N cats hats (where N is a constant), and so on. Finally, when the height of the cat is 1, it ends. The number of cats whose output height is not 1 and the total height of these cats is output. There are several special cases to note: In the first cat's hat, There is a cat with a height of 1, and in the other case, there is only one cat in each cat's hat.


Question: The Cat in the Hat

Background

(An homage to Theodore Seuss Geisel)

Salute to Theodore Seuss Geisel

The cat in the hat is a nasty creature,

The cat in the hat is a very annoying creature.
But the striped hat he is wearing has a rather nifty feature.

However, the striped hat he wore has an exquisite function.

With one flick of his wrist he pops his top off.

He shook his wrist and threw out his hat.

Do you know what's inside that cat's hat?

Do you know what is in this cat's hat?
A bunch of small cats, each with its own striped hat.

It's a group of kittens, and they all wear their own striped hats.

Each little cat does the same as line three,

Every kitten repeats the things in the third line.
All rights t the littlest ones, who just say ''why me? ''

Except for the smallest ones, they can only say, "Why am I ?"

Because the littlest cats have to clean all the grime,

Because the smallest cats need cleaning.
And they're tired of doing it time after time!

And they get tired of doing this over and over again.

The Problem

A clever cat walks into a messy room which he needs to clean. Instead of doing the work alone, it decides to have its helper cats do the W

A clever cat walked into a house that he needed to clean. He decided to let his helper cat do this, so that he would not have to do it.

Ork. It keeps its (smaller) helper cats inside its hat. Each helper CAT also has helper cats in its own hat, and so on. Eventually, the cats rea

He hid his helper cat in his hat. Each helper Cat's hat also has its own helper cat. Eventually, they found the smallest cat.

Ch a smallest size. These smallest cats have no additional cats in their hats. These unfortunate smallest cats have to do the cleaning.

No more cats are in the hats of the smallest cats. These unfortunate little cats can only do hygiene.

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

The number of cats in each cat's hat is a constant n. The height of the cat in the hat is the height of the cat that owns the hat. 1/(n + 1)

At whose hat they are in.

The smallest cats are of height one;
The minimum height of a cat is 1.
These are the cats that get the work done.
They are working cats.
All heights are positive integers.

The height of all cats is positive.

Given the height of the initial cat and the number of worker cats (of height one), find the number of cats that are not doing any work (cat

Given the height of the first cat and the number of working cats (the height is 1), find those who do not work (that is, the height is greater than 1)

S of height greater than one) and also determine the sum of all the cats 'heights (the height of a stack of all cats standing one on top of

And find the total height of all cats

Other ).

The input

The input consists of a sequence of cat-in-hat specifications. Each specification is a single line consisting of two positive integers, SEPA

Enter the parameter that contains a series of "Cats in hats. Each set of parameters has one row, which is composed of two positive integers separated by spaces.

Rated by white space. The first integer is the height of the initial cat, and the second integer is the number of worker cats.

The first integer is the height of the initial cat. The second parameter is the number of working cats.

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

A row composed of one to zero indicates that the input ends.

The output

For each input line (cat-in-hat specification), print the number of cats that are not working, followed by a space, followed by the height o

For each group of input, enter the number of inactive cats, output a space, and then output the total height of the cat. The row of '0 0' is not output

F The stack of cats. There shoshould be one output line for each input line other than the ''0 0'' that terminates input.

Sample Input

216 1255764801 16796160 0

Sample output

31 671335923 30275911

Source code:

# Include <stdio. h> int main () {long init, work_num, sum, num, T1, T2; long I, j, k; // freopen ("input.txt ", "r", stdin); While (scanf ("% LLD", & init, & work_num) {If (init = 0 & work_num = 0) break; If (init = work_num + 1) {// The initial Cat's hat contains the cat printf ("1% LLD \ n", work_num + init) with a height of 1 ); continue;} for (I = 1; I ++) {// find two consecutive integers as the base to make the number of the two numbers equal to T1 = Init; t2 = work_num; k = 0; while (t2% I = 0 & T1 % (I + 1) = 0) {T2/= I; T1/= (I + 1 ); K + = t2 ;/ /Number of cats not recorded as 1} If (T1 = 1 & t2 = 1) break;} sum = 0; num = 1; while (Init! = 1) {// total height sum + = init * num; init/= I + 1; num * = I;} sum + = work_num; printf ("% LLD \ n", K, sum);} return 0 ;}


Related Article

Contact Us

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.