X. Simple Math
Problem linkhttps://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/X
Score: 1
CPU: 1s
Memory: 512MB
CPU: 1s
Memory: 512MB
Recently a
Input
First you will be given an positive integer
Output
For each test case you have to print “
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
Input | Output |
---|---|
2 9 3 5 4 | Case 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