AT_abc466_f.Many Mod Calculation

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given integers N,XN,X and a length-NN sequence of positive integers A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N).

For a non-negative integer xx, define f(x)=(…((x mod A1) mod A2)…) mod ANf(x)=(\ldots((x \bmod A_1) \bmod A_2) \ldots ) \bmod A_N.

Find the number of integers xx between 11 and XX, inclusive, such that f(x)=0f(x)=0.

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

给你整数 N,XN,X 和一个长度为 NN 的正整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N)。

对于一个非负整数 xx,定义 f(x)=(…((x mod A1) mod A2)…) mod ANf(x)=(\ldots((x \bmod A_1) \bmod A_2) \ldots ) \bmod A_N。

求满足 f(x)=0f(x)=0 的整数 xx 的个数,其中 xx 的取值范围是 11 到 XX(含端点)。

你将得到 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 XX
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入给出,格式如下:

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

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

NN XX
A1A_1 A2A_2 …\ldots ANA_N

输出格式

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

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

输入输出样例

  • 输入#1

    4
    3 7
    5 2 3
    9 31415
    9 9 8 2 4 4 3 5 3
    1 1000000000000000000
    1
    9 20260405
    3141 5926 5358 9793 2384 6264 3383 2795 288

    输出#1

    4
    17452
    1000000000000000000
    77403

说明/提示

Sample 1 Explanation:
Consider the first test case.

For example, when x=7x=7, f(7)=(((7 mod 5) mod 2) mod 3)=(2 mod 2) mod 3=0 mod 3=0f(7)=(((7 \bmod 5) \bmod 2)\bmod 3)=(2\bmod 2)\bmod 3=0\bmod 3=0.

There are four integers xx between 11 and 77 such that f(x)=0f(x)=0: x=2,4,5,7x=2,4,5,7.

Constraints

  • 1≤T≤2×1051\le T\le 2\times 10^5
  • 1≤N≤2×1051\le N\le 2\times 10^5
  • The sum of NN over all test cases is at most 2×1052\times 10^5.
  • 1≤X≤10181\le X\le 10^{18}
  • 1≤Ai≤10181\le A_i\le 10^{18}
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

例如,当 x=7x=7 时,f(7)=(((7 mod 5) mod 2) mod 3)=(2 mod 2) mod 3=0 mod 3=0f(7)=(((7 \bmod 5) \bmod 2)\bmod 3)=(2\bmod 2)\bmod 3=0\bmod 3=0。

在 11 到 77 之间的整数 xx 中,满足 f(x)=0f(x)=0 的共有四个:x=2,4,5,7x=2,4,5,7。

约束条件

  • 1≤T≤2×1051\le T\le 2\times 10^5
  • 1≤N≤2×1051\le N\le 2\times 10^5
  • 所有测试用例的 NN 之和不超过 2×1052\times 10^5。
  • 1≤X≤10181\le X\le 10^{18}
  • 1≤Ai≤10181\le A_i\le 10^{18}
  • 所有输入值均为整数。

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

首页