AT_abc460_e.x + y ≡ x + y

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

For positive integers aa and bb, define concat(a,b)\mathrm{concat}(a, b) as the integer formed by writing aa and bb one after another. More formally, concat(a,b)\mathrm{concat}(a, b) is defined as follows.

  • Let AA and BB be the strings formed by writing aa and bb in decimal, respectively. Let CC be the string formed by concatenating AA and BB in this order. The value of CC interpreted as an integer in decimal notation is concat(a,b)\mathrm{concat}(a, b).

For example, if a=123a = 123 and b=45b = 45, then concat(a,b)=12345\mathrm{concat}(a, b) = 12345.

You are given positive integers NN and MM.
Find the number, modulo 998244353998244353, of pairs (x,y)(x, y) of positive integers not greater than NN such that concat(x,y)≡x+y(modM)\mathrm{concat}(x, y) \equiv x + y \pmod{M}.

You are given TT test cases; solve each one.

对于正整数 aa 和 bb,定义 concat(a,b)\mathrm{concat}(a, b) 为将 aa 和 bb 按顺序拼接后所得的整数。更形式化地,concat(a,b)\mathrm{concat}(a, b) 定义如下:

  • 设 AA 和 BB 分别为 aa 和 bb 的十进制表示所构成的字符串;令 CC 为按此顺序拼接 AA 和 BB 所得的字符串;则将 CC 视为十进制整数所得的值即为 concat(a,b)\mathrm{concat}(a, b)。

例如,若 a=123a = 123、b=45b = 45,则 concat(a,b)=12345\mathrm{concat}(a, b) = 12345。

给定正整数 NN 和 MM,
求满足 1≤x,y≤N1 \le x, y \le N 且 concat(x,y)≡x+y(modM)\mathrm{concat}(x, y) \equiv x + y \pmod{M} 的正整数对 (x,y)(x, y) 的个数(对 998244353998244353 取模)。

共给出 TT 组测试用例,请对每组分别求解。

输入格式

The input is given from Standard Input in the following format, where casei\mathrm{case}_i denotes the ii-th test case:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN MM

输入从标准输入给出,格式如下,其中 casei\mathrm{case}_i 表示第 ii 个测试用例:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例的格式如下:

NN MM

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.
For each test case, output the number, modulo 998244353998244353, of pairs (x,y)(x, y) satisfying the condition.

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。
对于每个测试用例,输出满足条件的数对 (x,y)(x, y) 的个数对 998244353998244353 取模的结果。

输入输出样例

  • 输入#1

    4
    3 2
    123 456
    20260530 460
    123456789123456789 998244353

    输出#1

    3
    0
    922576091
    422081792

说明/提示

Sample 1 Explanation:
For the first test case, three pairs (x,y)(x, y) satisfy the condition: (2,1),(2,2),(2,3)(2, 1), (2, 2), (2, 3).

Constraints

  • 1≤T≤1041 \leq T \leq 10^4
  • 1≤N≤10181 \leq N \leq 10^{18}
  • 2≤M≤1092 \leq M \leq 10^9
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,共有三对 (x,y)(x, y) 满足条件:(2,1),(2,2),(2,3)(2, 1), (2, 2), (2, 3)。

限制条件

  • 1≤T≤1041 \leq T \leq 10^4
  • 1≤N≤10181 \leq N \leq 10^{18}
  • 2≤M≤1092 \leq M \leq 10^9
  • 所有输入值均为整数。

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

首页