#P5517. [MtOI2019] 幻想乡数学竞赛
[MtOI2019] 幻想乡数学竞赛
Background
The annual Gensokyo Mathematics Contest (thMO) is about to begin again.
The young (actually old) girls (actually housewives) who study math in Gensokyo, together with the ice fairy baka, are preparing for thMO.
But at that moment, the day-by-day peace of Gensokyo was broken.
On the radio, a song of death started playing!
At that moment, people recalled the fear of being ruled by arithmetic again.
Only the voice of baka, baka, baka, baka echoed throughout Gensokyo.
Kawashiro Nitori is sitting in the thMO2019 exam room!
Because Nitori has her supercomputer, after successfully covering it with optical camouflage, she became unstoppable in the thMO2019 exam.
-
Nitori used her supercomputer to solve this problem in :
- ,given , find
-
Nitori: Obviously, this can be done with matrix multiplication + fast exponentiation, and you can pass it in , roughly like this:
But Nitori encountered a problem she cannot solve, and she is asking for your help!
Problem Description
There exists a sequence .
Given $a_0=-3,a_1=-6,a_2=-12,a_n=3a_{n-1}+a_{n-2}-3a_{n-3}+3^n$.
-
Now you are given a non-negative integer . Let . Please compute .
-
Note: if , please output .
To test your skills more thoroughly, Nitori prepared queries.
- To reduce the amount of input and output to some extent, we generate the queries using the following code:
namespace Mker
{
// Powered By Kawashiro_Nitori
// Made In Gensokyo, Nihon
#include<climits>
#define ull unsigned long long
#define uint unsigned int
ull sd;int op;
inline void init() {scanf("%llu %d", &sd, &op);}
inline ull ull_rand()
{
sd ^= sd << 43;
sd ^= sd >> 29;
sd ^= sd << 34;
return sd;
}
inline ull rand()
{
if (op == 0) return ull_rand() % USHRT_MAX + 1;
if (op == 1) return ull_rand() % UINT_MAX + 1;
if (op == 2) return ull_rand();
}
}
After calling Mker::init(), the value returned by your -th call to Mker::rand() is the of the -th query.
The constraints on are as follows:
-
If , then .
-
If , then .
-
If , then .
To reduce your output size, you only need to output the xor sum of the answers of all queries.
Input Format
The first line contains three integers: , , and .
Output Format
Output one integer: the xor sum of the answers to the queries.
142857 1145141919 0
562611141
142857 1145141919 1
894946216
142857 1145141919 2
771134436
Hint
Subtasks

Source
Lost Home 2019 League (MtOI2019) T4
Problem setter: disangan233
Problem tester: suwakow
Translated by ChatGPT 5