题解:P13561 「WWOI R1」WsW 的笔
Solution
容易看出,能凑成“一对”的数是很有限的,其中最大的一对是
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
int k,a,b;
const int P=1e9+7;
int qpow(int base,int exp){
int ret=1;
while(exp){
if(exp&1) ret=ret*base%P;
base=base*base%P;
exp>>=1;
}
return ret%P;
}
signed main(){
int T; cin>>T;
srand(time(0));
while(T--){
cin>>k;
cin>>a>>b;
// x x/k
// 0 1
// 1 0
// so a pair of (x,x/k) has two possiblity
// the max number which can be matched is b
// b can be matched with b/k
// so we have a range [a, b/k] that can be matched
int t=max(0ll,b/k-a+1);
int r=b-a+1-2*t;
int ans=qpow(2,t)%P*qpow(2,r)%P;
cout<<ans<<'\n';
}
}