-
Notifications
You must be signed in to change notification settings - Fork 0
/
loj1064.cpp
92 lines (80 loc) · 1.7 KB
/
loj1064.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//{ Template
using namespace std;
//{ C-headers
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <cctype>
#include <cassert>
#include <ctime>
//}
//{ C++-headers
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
//}
//}
//{ Floating-points
#define EPS DBL_EPSILON
#define abs(x) (((x) < 0) ? - (x) : (x))
#define zero(x) (abs (x) < EPS)
#define equal(a,b) (zero ((a) - (b)))
#define PI 2 * acos (0.0)
//}
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define INF 1<<29
#define ll long long
#define db double
#define NL puts("")
#define G getchar()
//}
int n,x;
ll dp[28][155];
ll gcd(ll a, ll b)
{
if(b==0) return a;
return gcd(b,a%b);
}
ll solve(int pos, int sum)
{
if(pos==n)
{
if(sum>=x) return 1;
return 0;
}
if(dp[pos][sum]!=-1) return dp[pos][sum];
ll res = 0;
for(int i=1;i<=6;i++)
res+=solve(pos+1,sum+i);
return dp[pos][sum] = res;
}
int main () {
int t,i,Case=1;
ll p,q,gd;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&x);
q=1;
for(i=1;i<=n;i++) q*=6;
memset(dp,-1,sizeof(dp));
p = solve(0,0);
//cout<<p<<" "<<q<<endl;
gd = gcd(p,q);
if(q/gd==1) printf("Case %d: %lld\n",Case++,p/gd);
else printf("Case %d: %lld/%lld\n",Case++,p/gd,q/gd);
}
return 0;
}