AT_arc221_a.Two Arithmetic Progressions

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given positive integers N,A,B,C,DN,A,B,C,D.

Find ∑i=1Ngcd⁡(Ai+B,Ci+D)\displaystyle \sum_{i=1}^N \gcd (Ai+B,Ci+D), modulo 998244353998244353. Here, gcd⁡(x,y)\gcd(x,y) denotes the greatest common divisor of xx and yy.

You are given TT test cases; solve each of them.

给定正整数 N,A,B,C,DN,A,B,C,D。

求 ∑i=1Ngcd⁡(Ai+B,Ci+D)\displaystyle \sum_{i=1}^N \gcd (Ai+B,Ci+D) 对 998244353998244353 取模的值。其中,gcd⁡(x,y)\gcd(x,y) 表示 xx 与 yy 的最大公约数。

你将得到 TT 组测试用例;请分别求解每一组。

输入格式

The input is given from Standard Input in the following format:

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

Each test case is given in the following format:

NN AA BB CC DD

输入从标准输入中按以下格式给出:

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

每个测试用例按以下格式给出:

NN AA BB CC DD

输出格式

Output the answers for the test cases in order, separated by newlines.

按顺序输出测试用例的答案,答案之间用换行符分隔。

输入输出样例

  • 输入#1

    3
    4 1 3 4 2
    100000000 1 1 1 2
    100000000 1 1 1 1

    输出#1

    10
    100000000
    822404071

说明/提示

Sample 1 Explanation:
For the first test case, the answer is gcd⁡(4,6)+gcd⁡(5,10)+gcd⁡(6,14)+gcd⁡(7,18)=2+5+2+1=10\gcd(4,6)+\gcd(5,10)+\gcd(6,14)+\gcd(7,18)=2+5+2+1=10.

Constraints

  • 1≤T≤2001\leq T\leq 200
  • 1≤N≤1091\leq N\leq 10^9
  • 1≤A,B,C,D≤1041\leq A,B,C,D\leq 10^4
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,答案为 gcd⁡(4,6)+gcd⁡(5,10)+gcd⁡(6,14)+gcd⁡(7,18)=2+5+2+1=10\gcd(4,6)+\gcd(5,10)+\gcd(6,14)+\gcd(7,18)=2+5+2+1=10。

约束条件

  • 1≤T≤2001\leq T\leq 200
  • 1≤N≤1091\leq N\leq 10^9
  • 1≤A,B,C,D≤1041\leq A,B,C,D\leq 10^4
  • 所有输入值均为整数。

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

首页