2023 rcpc
This commit is contained in:
43
2023/rcpc/d2/editorial/e-fiboxor-589.cpp
Normal file
43
2023/rcpc/d2/editorial/e-fiboxor-589.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int mod;
|
||||
|
||||
long long pw(long long b, int e)
|
||||
{
|
||||
long long ans = 1;
|
||||
while(e)
|
||||
{
|
||||
if(e & 1)
|
||||
ans = (ans * b) % mod;
|
||||
b = (b * b) % mod;
|
||||
e >>= 1;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
long long solve(int x)
|
||||
{
|
||||
if(x % 2 == 0)
|
||||
return (2LL * (pw(2, x/2) - 1)) % mod;
|
||||
else
|
||||
{
|
||||
return (2LL * (pw(2, x/2) - 1) % mod + pw(2, x/2)) % mod;
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
|
||||
for(; t; t--)
|
||||
{
|
||||
int L, R;
|
||||
cin >> L >> R >> mod;
|
||||
cout << (solve(R) - solve(L-1) + mod) % mod << '\n';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user