链接:https://ac.nowcoder.com/acm/contest/11746/H
来源:牛客网
题目描述
憨憨小杨晚上睡不着觉,就开始数羊,她觉得一只一只数太慢了,突发奇想出了一种新的数羊方式,羊羊数量A(n,m)由两个整形变量n和m决定,计算方式如下:
现在给出n和m的值,请你帮小杨数数一共有多少只羊。
输入描述:
多组输入。
第一行包含一个整数T(1≤T≤1000),表示有T组测试数据。
每组测试数据包含一行,包含两个整数n(1≤n≤10^9)和m(0≤m≤2).
输出描述:
对每一组输入,在一行中输出A(n,m)的值,由于输出的结果可能会很大,答案对998244353取模
示例1
输入
3
3 0
3 1
3 2
输出
5
6
8
答案如下
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod =998244353;
ll quick_mod(ll a,ll m)
{
ll ans=1;
while(m)
{
if(m%2==1) ans=ans*a%mod;
a=a*a%mod;
m/=2;
}
return ans%mod;
}
int main()
{
int t;
ll n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
ll ans=0;
if(m==0)
{
if(n==1) ans+=2;
else ans+=(n+2);
}
else if(m==1)
{
ans=n*2;
}
else if(m==2)
{
ans=quick_mod(2,n);
}
cout<<ans%mod<<endl;
}
return 0;
}