CF1864H.Asterism Stream

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bogocubic is playing a game with amenotiomoi. First, Bogocubic fixed an integer nn, and then he gave amenotiomoi an integer xx which is initially equal to 11.

In one move amenotiomoi performs one of the following operations with the same probability:

  • increase xx by 11;
  • multiply xx by 22.

Bogocubic wants to find the expected number of moves amenotiomoi has to do to make xx greater than or equal to nn. Help him find this number modulo 998 244 353998\,244\,353.

Formally, let M=998 244 353M = 998\,244\,353. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output such an integer yy that 0≤y<M0 \le y \lt M and y⋅q≡p(modM)y \cdot q \equiv p \pmod{M}.

Bogocubic 正在与 amenotiomoi 玩一个游戏。首先,Bogocubic 固定一个整数 nn,然后他给 amenotiomoi 一个初始值为 11 的整数 xx。

在每一步中,amenotiomoi 以相同概率执行以下两种操作之一:

  • 将 xx 加 11;
  • 将 xx 乘以 22。

Bogocubic 想要求出 amenotiomoi 使得 xx 大于或等于 nn 所需的期望步数。请帮助他求出该期望值对 998 244 353998\,244\,353 取模的结果。

形式化地,令 M=998 244 353M = 998\,244\,353。可以证明,答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出满足 p⋅q−1 mod Mp \cdot q^{-1} \bmod M 的整数。换言之,输出满足 0≤y<M0 \le y < M 且 y⋅q≡p(modM)y \cdot q \equiv p \pmod{M} 的整数 yy。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The only line of each test case contains one integer nn (1≤n≤10181 \le n \le 10^{18}).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤10181 \le n \le 10^{18})。

输出格式

For each test case, output a single integer — the expected number of moves modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——即期望移动次数对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    7
    1
    4
    8
    15
    998244353
    296574916252563317
    494288321850420024

    输出#1

    0
    499122179
    717488133
    900515847
    93715054
    44488799
    520723508

说明/提示

In the first test case, n≤xn\le x without any operations, so the answer is 00.

In the second test case, for n=4n = 4, here is the list of all possible sequences of operations and their probabilities:

  • 1⟶+12⟶+13⟶+141\stackrel{+1}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{+1}{\longrightarrow}4, the probability is 18\frac{1}{8};
  • 1⟶×22⟶+13⟶+141\stackrel{\times 2}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{+1}{\longrightarrow}4, the probability is 18\frac{1}{8};
  • 1⟶+12⟶+13⟶×261\stackrel{+1}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{\times 2}{\longrightarrow}6, the probability is 18\frac{1}{8};
  • 1⟶×22⟶+13⟶×261\stackrel{\times 2}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{\times 2}{\longrightarrow}6, the probability is 18\frac{1}{8};
  • 1⟶+12⟶×241\stackrel{+1}{\longrightarrow}2\stackrel{\times 2}{\longrightarrow}4, the probability is 14\frac{1}{4};
  • 1⟶×22⟶×241\stackrel{\times 2}{\longrightarrow}2\stackrel{\times 2}{\longrightarrow}4, the probability is 14\frac{1}{4}.

So the expected number of moves is 4⋅(3⋅18)+2⋅(2⋅14)=52≡499122179(mod998244353)4 \cdot \left(3 \cdot \frac{1}{8}\right) + 2 \cdot \left(2 \cdot \frac{1}{4} \right) =\frac{5}{2} \equiv 499122179 \pmod{998244353}.

In the third test case, for n=8n = 8, the expected number of moves is 13732≡717488133(mod998244353)\frac{137}{32}\equiv 717488133\pmod{998244353}.

In the fourth test case, for n=15n = 15, the expected number of moves is 249774096≡900515847(mod998244353)\frac{24977}{4096} \equiv 900515847 \pmod{998244353}.

在第一个测试用例中,无需任何操作即有 n≤xn\le x,因此答案为 00。

在第二个测试用例中,当 n=4n = 4 时,以下是所有可能的操作序列及其对应概率:

  • 1⟶+12⟶+13⟶+141\stackrel{+1}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{+1}{\longrightarrow}4,概率为 18\frac{1}{8};
  • 1⟶×22⟶+13⟶+141\stackrel{\times 2}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{+1}{\longrightarrow}4,概率为 18\frac{1}{8};
  • 1⟶+12⟶+13⟶×261\stackrel{+1}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{\times 2}{\longrightarrow}6,概率为 18\frac{1}{8};
  • 1⟶×22⟶+13⟶×261\stackrel{\times 2}{\longrightarrow}2\stackrel{+1}{\longrightarrow}3\stackrel{\times 2}{\longrightarrow}6,概率为 18\frac{1}{8};
  • 1⟶+12⟶×241\stackrel{+1}{\longrightarrow}2\stackrel{\times 2}{\longrightarrow}4,概率为 14\frac{1}{4};
  • 1⟶×22⟶×241\stackrel{\times 2}{\longrightarrow}2\stackrel{\times 2}{\longrightarrow}4,概率为 14\frac{1}{4}。

因此,操作步数的期望值为 4⋅(3⋅18)+2⋅(2⋅14)=52≡499122179(mod998244353)4 \cdot \left(3 \cdot \frac{1}{8}\right) + 2 \cdot \left(2 \cdot \frac{1}{4} \right) =\frac{5}{2} \equiv 499122179 \pmod{998244353}。

在第三个测试用例中,当 n=8n = 8 时,操作步数的期望值为 13732≡717488133(mod998244353)\frac{137}{32}\equiv 717488133\pmod{998244353}。

在第四个测试用例中,当 n=15n = 15 时,操作步数的期望值为 249774096≡900515847(mod998244353)\frac{24977}{4096} \equiv 900515847 \pmod{998244353}。

输入解题思路,AI测评打分。不知道怎么写?

首页