跳到正文

题解

timu

jiazihan1208约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年7月13日
收录
2026年7月13日
更新
2026年11月13日
篇幅
约 3 分钟
获赞
1

版本

  1. v1当前

AT_abc466_f [ABC466F] Many Mod Calculation

题目描述

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.

输入格式

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

输出格式

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

输入输出样例 #1

输入 #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 Explanation 1

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.
原文