思路跟题解一样,就是(2p−1)(⌊4l2⌋).
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll T,n,m;
int main(){
ios::sync_with_stdio(0);
cin>>T;
while(T--){
cin>>n>>m;
if(n==1){puts("0");continue;}
while(n&(n-1)) n&=n-1;
cout<<(n*2-1)%mod*(m*m/4)%mod<<'\n';
}
return 0;
}