题解 | #好好好数组#
好好好数组
https://www.nowcoder.com/practice/bacd2c7176e945ee88e7d83c6019613d
注意到题面当中 。说明对于一个数组当中
确定后,剩下的所有元素可以由后一个元素推得,所以不同的数组至多有
种。
对于取模运算有 ,基于此性质接下来对
的情况进行讨论:
当 时,
,直到
处变成
,因此有三个不同的数字。
当 时,
(末尾的若干个元素全部相等),直到
处变成
,因此有两个不同的数字。
当 时,所有元素都为
,因此仅有一个不同的数字。
分类讨论即可,记得特判 。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL maxn=1100000,M=998244353;
LL T,n,m,ans=0,a[maxn]={};
void solve(){
scanf("%lld%lld",&n,&m);
if(n==1){
if(m==1)ans=2;
else ans=0;
}
else if(n==2){
if(m==1)ans=3;
else if(m==2)ans=2;
else ans=0;
}
else{
if(m==1)ans=n+1;
else if(m==2)ans=n;
else if(m==3)ans=1;
else ans=0;
}
printf("%lld\n",ans);
}
int main(){
scanf("%lld",&T);
while(T--)solve();
return 0;
}
