2023 rcpc

This commit is contained in:
2024-04-22 16:45:09 +03:00
parent a0ddb657b7
commit 156202ada0
61 changed files with 4462 additions and 0 deletions

View 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;
}