A xor B plus C

AtCoder
IDttpc2024_1_d
Time8000ms
Memory256MB
Difficulty
You are given non-negative integers $A$, $B$, and $C$. Define a sequence of non-negative integers $X = (X_1, X_2, \dots)$ as follows: * $X_1 = A$ * $X_2 = B$ * $X_{i+2} = (X_i \oplus X_{i+1}) + C\ \ (i=1,2,\dots)$ Here, $\oplus$ represents the bitwise XOR operation. You are also given a positive integer $N$. Calculate $X_N \bmod 998244353$. ## Constraints * All input values are integers. * $0 \leq A, B, C < 2^{20}$ * $1 \leq N \leq 10^{18}$ ## Input The input is given from Standard Input in the following format: $A$ $B$ $C$ $N$ [samples]
Samples
Input #1
1 2 3 4
Output #1
7

$X = (1, 2, 6, 7, \dots)$. Here, $X_4 = 7$ is the answer.
Input #2
123 456 789 123456789
Output #2
567982455
Input #3
0 0 0 1000000000000000000
Output #3
0
API Response (JSON)
{
  "problem": {
    "name": "A xor B plus C",
    "description": {
      "content": "You are given non-negative integers $A$, $B$, and $C$. Define a sequence of non-negative integers $X = (X_1, X_2, \\dots)$ as follows: *   $X_1 = A$ *   $X_2 = B$ *   $X_{i+2} = (X_i \\oplus X_{i+1}) +",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 8000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "ttpc2024_1_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given non-negative integers $A$, $B$, and $C$. Define a sequence of non-negative integers $X = (X_1, X_2, \\dots)$ as follows:\n\n*   $X_1 = A$\n*   $X_2 = B$\n*   $X_{i+2} = (X_i \\oplus X_{i+1}) +...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments