AT_abc466_f.Many Mod Calculation
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given integers N,X and a length-N sequence of positive integers A=(A1,A2,…,AN).
For a non-negative integer x, define f(x)=(…((xmodA1)modA2)…)modAN.
Find the number of integers x between 1 and X, inclusive, such that f(x)=0.
You are given T test cases; solve each of them.
给你整数 N,X 和一个长度为 N 的正整数序列 A=(A1,A2,…,AN)。
对于一个非负整数 x,定义 f(x)=(…((xmodA1)modA2)…)modAN。
求满足 f(x)=0 的整数 x 的个数,其中 x 的取值范围是 1 到 X(含端点)。
你将得到 T 组测试数据;请对每组数据求解。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N X
A1 A2 … AN
输入从标准输入给出,格式如下:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
N X
A1 A2 … AN
输出格式
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=7, f(7)=(((7mod5)mod2)mod3)=(2mod2)mod3=0mod3=0.
There are four integers x between 1 and 7 such that f(x)=0: x=2,4,5,7.
Constraints
- 1≤T≤2×105
- 1≤N≤2×105
- The sum of N over all test cases is at most 2×105.
- 1≤X≤1018
- 1≤Ai≤1018
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
例如,当 x=7 时,f(7)=(((7mod5)mod2)mod3)=(2mod2)mod3=0mod3=0。
在 1 到 7 之间的整数 x 中,满足 f(x)=0 的共有四个:x=2,4,5,7。
约束条件
- 1≤T≤2×105
- 1≤N≤2×105
- 所有测试用例的 N 之和不超过 2×105。
- 1≤X≤1018
- 1≤Ai≤1018
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?