Hdu 4927 Series 1 (large number template addition, subtraction, multiplication, division)

Source: Internet
Author: User

Hdu 4927 Series 1 (large number template addition, subtraction, multiplication, division)

Series 1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission (s): 1067 Accepted Submission (s): 390


Problem DescriptionLet A be an integral series {A1, A2,..., }.

The zero-order series of A is A itself.

The first-order series of A is {B1, B2,..., Bn-1}, where Bi = Ai + 1-Ai.

The ith-order series of A is the first-order series of its (I-1) th-order series (2 <= I <= n-1 ).

Obviusly, the (n-1) th-order series of A is a single integer. Given A, figure out that integer.
InputThe input consists of several test cases. The first line of input gives the number of test cases T (T <= 10 ).

For each test case:
The first line contains a single integer n (1 <= n <= 3000), which denotes the length of series.
The second line consists of n integers, describing A1, A2,..., An. (0 <= Ai <= 105)

OutputFor each test case, output the required integer in a line.
Sample Input
231 2 341 5 7 2

Sample Output
0-5

AuthorBUPT
Source2014 Multi-University Training Contest 6

The formula is as follows: C (n, n-1) = C (n, n) * n/1; C (n, N-2) = C (n, n-1) * (n-1)/2;


# Include "stdio. h "# include" string. h "# include" iostream "# include" algorithm "using namespace std; # define LL _ int64 # define N 300 # define M 100000000000 # define max (a, B) (a> B? A: B) int a [3010]; LL c [N], ans [N], cc [N]; // array size. The length of the first element of the array contains a large number, if the length is negative, it indicates that the large number is smaller than zero void mul (LL * c, int x) // a large number is multiplied by an integer {int I; for (I = 1; I <= c [0]; I ++) c [I] = c [I] * x; for (I = 1; I <= c [0]; I ++) {c [I + 1] + = c [I]/M; c [I] = c [I] % M ;} while (c [c [0] + 1]) {c [0] ++; c [c [0] + 1] = c [c [0]/M; c [c [0] % = M ;}} void div (LL * c, int y) // divide a large number by an integer {int I; for (I = c [0]; I> 1; I --) {c [I-1] + = (c [I] % y) * M; c [I]/= y;} c [1]/= y; while (c [c [0] = 0) c [0] --;} void add (LL * ans, LL * c) // add a large number to a large number, and save the result to ans {int f =-1, I; if (ans [0] <0) {if (-ans [0]> c [0]) f = 1; else if (-ans [0]
 
  
0; I --) if (ans [I]> c [I]) {f = 1; break;} else if (ans [I]
  
   
C [0]) f = 1; else if (ans [0]
   
    
0; I --) if (ans [I]> c [I]) {f = 1; break;} else if (ans [I]
    
     
0) {mul (c, n-I); div (c, I);} memcpy (cc, c, sizeof (c); mul (c, a [I]); if (flag = 1) add (ans, c); else sub (ans, c); flag * =-1; memcpy (c, cc, sizeof (cc);} if (ans [0] <0) {printf ("-"); ans [0] =-ans [0];} printf ("% I64d", ans [ans [0]); for (I = ans [0]-1; I> 0; I --) printf ("% 011I64d", ans [I]); printf ("\ n");} 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.