「PEOI Rd1」异或(xor)

Luogu
IDLGP9223
Time1000ms
Memory128MB
DifficultyP3
O2优化
给定两个正整数 $n,m$,求: $$\sum_{i=1}^{n}\sum_{j=1}^{m}\left(i \oplus j\right) $$ 其中,$\oplus$ 表示按位异或运算(即 C++ 中的 `^` 符号)。答案对 $998244353$ 取模。 ## Input 本题包含多组数据。 第一行输入一个整数 $T$,表示数据组数。 接下来 $T$ 行,每行输入两个整数 $n,m$。 ## Output 输出共 $T$ 行,每行一个整数,表示每组询问的答案。 [samples] ## Note #### 样例解释 第一个样例第一组数据: $\begin{aligned}&(1 \oplus 1)+(1 \oplus 2)+(2 \oplus 1)+(2 \oplus 2)\\=\ &0+3+3+0\\=\ &6\end{aligned}$ 第二组数据: $\begin{aligned}&(1 \oplus 1)+(1 \oplus 2)+(1 \oplus 3)+(2 \oplus 1)+(2 \oplus 2)+(2 \oplus 3)+(3 \oplus 1)+(3 \oplus 2)+(3 \oplus 3)\\=\ &0+3+2+3+0+1+2+1+0\\=\ &12\end{aligned}$ --- #### 数据范围 |子任务|$n,m \leq$|特殊性质|分值| |:-:|:-:|:-:|:-:| |$1$|$10^3$|无|$10$| |$2$|$10^6$|无|$20$| |$3$|$10^{16}$|A|$20$| |$4$|$10^{16}$|无|$50$| - 特殊性质 A:保证 $n=2^p-1$,$m=2^q-1$,其中 $p,q\in\mathbb Z$。 对于 $100\%$ 的数据,保证 $1 \leq n,m \leq 10^{16}$,$1 \leq T \leq 50$。
Samples
Input #1
2
2 2
3 3
Output #1
6
12
Input #2
2
4 8
8 9
Output #2
144
420
API Response (JSON)
{
  "problem": {
    "name": "「PEOI Rd1」异或(xor)",
    "description": {
      "content": "给定两个正整数 $n,m$,求: $$\\sum_{i=1}^{n}\\sum_{j=1}^{m}\\left(i \\oplus j\\right) $$ 其中,$\\oplus$ 表示按位异或运算(即 C++ 中的 `^` 符号)。答案对 $998244353$ 取模。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 131072
    },
    "difficulty": {
      "LuoguStyle": "P3"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP9223"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "给定两个正整数 $n,m$,求:\n\n$$\\sum_{i=1}^{n}\\sum_{j=1}^{m}\\left(i \\oplus j\\right) $$\n\n其中,$\\oplus$ 表示按位异或运算(即 C++ 中的 `^` 符号)。答案对 $998244353$ 取模。\n\n## Input\n\n本题包含多组数据。\n\n第一行输入一个整数 $T$,表示数据组数。\n\n接下来 $T$ 行,每行输入两个整数 $n...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments