很简单的博弈题.....算几组能得到规律了。
某个状态先手要赢 等价于 之前有一种状态是后手赢,先手可以保证让现在这个状态到达那个状态
#include<cstdio> #include<cstring> #include<ctime> #include<algorithm> using namespace std; const int maxn = 10000 + 10; int a[maxn], b[maxn]; int n, m; int gcd(int a, int b) { int t; while (b) { t = a%b; a = b; b = t; } return a; } void init() { for (int i = 1; i <= 10000; i++) a[i] = i, b[i] = i; for (int i = 3; i <= 10000; i = i + 3) { swap(b[i - 1], b[i - 2]); } b[10000] = 10001; } int main() { init(); while (~scanf("%d%d", &n, &m)){ int tot = 0; for (int i = 1; i <= 10000; i++) if (a[i] <= n&&b[i] <= m) tot++; int fz, fm; fz = tot; fm = m*n; if (tot == 0) fz = 0, fm = 1; else { int a=fz / gcd(fz, fm),b = fm / gcd(fz, fm); fz = a; fm = b; } printf("%d/%d ", fz, fm); } return 0; }