1 solutions

  • 0
    @ 2025-11-5 17:22:07

    C++ :

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const long long mod=(long long )(1e9+7);
    int n,k;
    
    long long power(long long a,long long p)
    {
        long long res=1;
        while(p)
        {
            if(p&1)
                res=(a*res)%mod;
                a=(a*a)%mod;
                p>>=1;
        }
        return res;
    }
    long long solve(long long x)
    {
        long long res;
        if(x==1) return 1;
        if(x==2) return 2;
        if(x==3) return 5;
        res=(power(2,x-1)%mod+((x-2)*power(2,x-3)%mod))%mod;
        return res;
    }
    int main()
    {
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&k);
    
            if(k>n)
            {
                printf("0\n");
                continue;
            }
            int x=n;
            x-=(k-1);
            printf("%lld\n",solve(x));
        }
        return 0;
    }
    
    
    • 1

    Information

    ID
    18351
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By