UVa 369 combinations: How to use double to combine numbers

Source: Internet
Author: User
Tags time limit

369-combinations

Time limit:3.000 seconds

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

Computing the exact number of ways that N things can is taken m at a time can is a great challenge when nand/or M become v ery large. Challenges are the stuff of contests. Therefore, you are to make just such a computation given the following:

GIVEN:

Compute the EXACT value of:

You may assume that final value of C would fit in a 32-bit Pascal longint or a C long.

For the record, the exact value of 100! is:

     93,326,215,443,944,152,681,699,238,856,266,700,490,715,968,264,381,621,
        468,592,963,895,217,599,993,229,915,608,941,463,976,156,518,286,253,
        697,920,827,223,758,251,185,210,916,864,000,000,000,000,000,000,000,000

Input and Output

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45361.htm

The input to this program would be one or more lines each containing zero or more leading spaces, a value forn, one or more Spaces, and a value for M. The last line of the input file would contain a dummy N, M pair with both values equal to zero. Your program should terminate "when this" is read.

The output from this program should is in the form:

N things taken M at a time is C exactly.

Sample Input

       6  5  6
       0  0

Sample Output

Things taken 6 at A/A is 1192052400 exactly.
Things taken 5 at A/A is 15504 exactly.
Things taken 6 at A/A is 18564 exactly.

Note this sentence:

"You may assume that final value of C would fit in a 32-bit Pascal longint or a C long."

Complete code:

/*0.022s*/
     
#include <cstdio>  
     
int main ()  
{  
    int N, M, I;  
    Double C;  
    while (scanf ("%d%d", &n, &m), N)  
    {  
        C = 1.0;  
        for (i = N; i > N-m-I.) C *= (double) I;  
        for (i = 2; I <= M ++i) C/= (double) I;  
        printf ("%d things taken%d at a time is%.0f exactly.\n", N, M, C);  
    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.