紫书上推出来的公式1-(k+1)/2^(k)
注意范围 都用的long long
#include<cstdio> #include<iostream> #include<cmath> using namespace std; typedef long long ll; ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); } int main() { int n,kase=1; scanf("%d",&n); while(n--){ ll N,K; scanf("%lld%lld",&N,&K); printf("Case #%d: ",kase++); ll a = ((ll)1<<K) - K - 1; ll b = ((ll)1<<K); if(a==0) printf("0/1\n"); else { ll gd=gcd(a,b); a/=gd; b/=gd; printf("%lld/%lld\n",a,b); } } return 0; }
时间: 2024-11-26 15:01:45