HDU 4165 Pills (catlan number)

Source: Internet
Author: User
View code

# Include <iostream>
Using Namespace STD;

# Define Maxcompute 100

# Define Base 10000

Void Multiply ( Int A [], Int Max, Int B) // The multiplication of large numbers. Pay attention to parameter transmission.

{

Int I, array = 0 ;

For (I = max- 1 ; I> = 0 ; I --)

{

Array + = B * A [I];

A [I] = array % base; // Each digit in the array contains four digits with a large number.

Array/= base;

}

}

Void Divide ( Int A [], Int Max, Int B) // Simulate division of large numbers

{

Int I, DIV = 0 ;

For (I = 0 ; I <Max; I ++)

{

DIV = div * base + A [I];

A [I] = div/B;

Div % = B;

}

}

Int Main ()

{

Int A [ 101 ] [Max], I, N;

Memset ([ 1 ], 0 , Max *Sizeof ( Int ));

For (I = 2 , [ 1 ] [Max- 1 ] = 1 ; I < 101 ; I ++) // High coordinate storage of large numbers low

{

Memcpy (A [I], a [I- 1 ], Max *Sizeof ( Int )); // H [I] = H [I-1];

Multiply (A [I], Max, 4 * I- 2 ); // H [I] * = (4 * I-2 );

Divide (A [I], Max, I + 1 ); // H [I]/= (I + 1 );

}

While (CIN> N & N)

{

For (I = 0 ; I <Max & a [n] [I] = 0 ; I ++ ); // Remove the number 0 before the array.

Cout <a [n] [I ++]; // Output the first non-zero number

For (; I <Max; I ++)

{

Printf ( " % 04d " , A [n] [I]); // Output The number next to it, and each person must be 4 characters in length! (32767)

}

Cout <Endl;

}

Return 0 ;

}

 

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.