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
| #include<bits/stdc++.h> #define pf printf #define sc(x) scanf("%d", &x) #define scl(x) scanf("%lld", &x) using namespace std; typedef long long ll; typedef pair<ll,ll> pii; int ff; queue<pii>q; map<pii,int>mp; void dfs(ll x,ll y){ if(ff) return; if(mp.count(pii(x,y))) return; if(x==y){ ff++; return; } if(__gcd(x,y)==1) return; q.push(pii(x,y)); mp[pii(x,y)]=1; dfs(x+1,y); dfs(x,y+1); dfs(x-1,y); dfs(x,y-1); dfs(x+1,y+1); dfs(x+1,y-1); dfs(x-1,y+1); dfs(x-1,y-1); } int cal(ll x,ll y){ int ans(0); if(mp.count(pii(x-1,y))) ans++; if(mp.count(pii(x,y-1))) ans++; if(mp.count(pii(x+1,y))) ans++; if(mp.count(pii(x,y+1))) ans++; if(mp.count(pii(x-1,y-1))) ans++; if(mp.count(pii(x-1,y+1))) ans++; if(mp.count(pii(x+1,y-1))) ans++; if(mp.count(pii(x+1,y+1))) ans++; return ans; } int solve(){ ll x,y; scl(x); scl(y); mp.clear(); ff=0; while(!q.empty()) q.pop(); dfs(x,y); if(ff) return pf("0/1\n"); ll sz=q.size(),ans=sz,cnt=1+cal(x,y); while(!q.empty()){ ll x=q.front().first,y=q.front().second; q.pop(); if(mp.count(pii(x-1,y))) ans++; if(mp.count(pii(x,y-1))) ans++; if(mp.count(pii(x+1,y))) ans++; if(mp.count(pii(x,y+1))) ans++; if(mp.count(pii(x-1,y-1))) ans++; if(mp.count(pii(x-1,y+1))) ans++; if(mp.count(pii(x+1,y-1))) ans++; if(mp.count(pii(x+1,y+1))) ans++; } ll g=__gcd(ans,cnt); ans/=g; cnt/=g; return pf("%lld/%lld\n",cnt,ans); } int main(){ int _; sc(_); while(_--) solve(); }
|