Combination Math + large number multiplication + large number of divisions HDU 1261 strings

Source: Internet
Author: User

//[3/17/2015 jmings]/* This problem can be deduced directly from the formula:{(a1+a2+......+an)!     {a1! A2!...... an!}

because (12x26)! = 312! can only be stored through an array, so it involves "large number multiplication" and "large number division", the main idea of large number realization simulation hand calculation, specific reference program.  */
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cstring>5 using namespacestd;6 Const intMAX = -;7 8 intN, arr[ -];9 intTotal ;Ten intAns[max], Len; One  A //factorial - voidFactorial (int_n,int_arr[],int&_len) { -      for(intnum =2; Num <= _n; ++num) { the         intCNT =0, val, carry =0; -          for(CNT < _len; + +)CNT) { -val = _arr[cnt] * num +carry; -_ARR[CNT] = val%Ten; +Carry = val/Ten; -         } +          while(carry) { A_arr[_len++] = carry%Ten; atCarry/=Ten; -         } -     } - } -  - //Large Number Division in voidDiv (intdata) { -     intcarry =0; to     intVal; +      for(inti = len-1; I >=0; --i) { -val = ans[i] + carry *Ten; theAns[i] = val/data; *carry = val%data; $     }Panax Notoginseng      while(0= = Ans[len-1]) { ---Len; the     } + } A  the voidSolve () { +      for(inti =0; I < n; ++i) { -          for(intj =2; J <= Arr[i]; ++j) { $ Div (j); $         } -     } - } the  - intMain ()Wuyi { the     //freopen ("Input.txt", "R", stdin); -     //freopen ("Output.txt", "w", stdout); Wu      while(~SCANF ("%d", &n) &&N) { -Total =0; About          for(inti =0; I < n; ++i) { $scanf"%d", &arr[i]); -Total + =Arr[i]; -         } -ans[0] =1; ALen =1; + factorial (total, Ans, Len); the Solve (); -          for(inti = len-1; I >=0; --i) { $printf"%d", Ans[i]); the         } theprintf"\ n"); the     } the     return 0; -}



Combination Math + large number multiplication + large number of divisions HDU 1261 strings

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.