Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Monday 31 October 2016


X. Simple Math
Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/X


Score: 1

CPU: 1s
Memory: 512MB

Recently a Mathematics contest held on Saint Martin Island where only one problem was given to the participants. Unfortunately all the contestants have solved the problem. So they all win the competition. But only T number of trophies will be given to the winners. Now as all of them won the contest. How many ways we can give T trophies to N participants, where T is always smaller than N

Input
First you will be given an positive integer X (1< X < 100), the number of test case. One line for each test case. For each test case you will be given two space separated integers N and T ( 1 <= T < N < 20 )

Output
For each test case you have to print “Case X: W”, where X is the case number and W is the number of ways we can give T trophies to N participants.

Sample

InputOutput
2 9 3 5 4Case 1: 504 Case 2: 120

Solution

#include<stdio.h>
int main()
{
    int i,j,k,a,b,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        long long res1=0,res2=1,res3=1,res=0;
        scanf("%d%d",&a,&b);
        for(j=1;j<=a;j++){
                res2=res2*j;
        }
        res1=a-b;
        for(k=1;k<=res1;k++){
            res3=res3*k;
        }
        res=res2/res3;
        printf("Case %d: %lli\n",i,res);
    }
    return 0;
}

No comments:

Post a Comment