这题有空再看看
Description
n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x?
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each test case contains two integers n (1 ≤ n < 25) and x (0 ≤ x < 150). The meanings of n and x are given in the problem statement.
Output
For each case, output the case number and the probability in 'p/q' form where p and q are relatively prime. If q equals 1 then print p only.
Sample Input
7
3 9
1 7
24 24
15 76
24 143
23 81
7 38
Sample Output
Case 1: 20/27
Case 2: 0
Case 3: 1
Case 4: 11703055/78364164096
Case 5: 25/4738381338321616896
Case 6: 1/2
Case 7: 55/46656
#include <cstdio>
#include <cstring>
int n,m,p[25];
long long v,sum,dp[30][150];
long long gcd(long long a,long long b)
{
if(a%b==0) return b;
else return gcd(b,a%b);
}
int main()
{
int r,ca=1;
scanf("%d",&r);
while(r--)
{
scanf("%d%d",&n,&m);
if(!n&&!m) break;
if(n>=m) printf("Case %d: 1\n",ca++);
else if(n*6<m) printf("Case %d: 0\n",ca++);
else
{
v=1,sum=0;
for(int i=0; i<n; ++i) v=v*6;
memset(dp,0,sizeof(dp));
for(int i=0; i<=6; ++i) dp[0][i]=1;
for(int i=0; i<n-1; ++i)
for(int j=1; j<=(i+1)*6; ++j)
for(int k=1; k<=6; ++k)
dp[i+1][j+k]+=dp[i][j];
for(int i=m; i<=n*6; ++i)
sum=sum+dp[n-1][i];
long long c=gcd(v,sum);
printf("Case %d: %lld/%lld\n",ca++,sum/c,v/c); //I64d
}
}
return 0;
}