Turtle Tenacity: Continual Mods
D. Turtle Tenacity: Continual Mods
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Given an array
a
1
,
a
2
,
…
,
a
n
a_1, a_2, \ldots, a_n
a1,a2,…,an, determine whether it is possible to rearrange its elements into
b
1
,
b
2
,
…
,
b
n
b_1, b_2, \ldots, b_n
b1,b2,…,bn, such that
b
1
m
o
d
b
2
m
o
d
…
m
o
d
b
n
≠
0
b_1 \bmod b_2 \bmod \ldots \bmod b_n \neq 0
b1modb2mod…modbn=0.
Here
x
m
o
d
y
x \bmod y
xmody denotes the remainder from dividing
x
x
x by
y
y
y. Also, the modulo operations are calculated from left to right. That is,
x
m
o
d
y
m
o
d
z
=
(
x
m
o
d
y
)
m
o
d
z
x \bmod y \bmod z = (x \bmod y) \bmod z
xmodymodz=(xmody)modz. For example,
2024
m
o
d
1000
m
o
d
8
=
(
2024
m
o
d
1000
)
m
o
d
8
=
24
m
o
d
8
=
0
2024 \bmod 1000 \bmod 8 = (2024 \bmod 1000) \bmod 8 = 24 \bmod 8 = 0
2024mod1000mod8=(2024mod1000)mod8=24mod8=0.
Input
The first line of the input contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n n n ( 2 ≤ n ≤ 1 0 5 2 \le n \le 10^5 2≤n≤105).
The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1≤ai≤109).
The sum of
n
n
n over all test cases does not exceed
2
⋅
1
0
5
2 \cdot 10^5
2⋅105.
Output
For each test case, output “YES” if it is possible, “NO” otherwise.
You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.
题面翻译
给定一个长度为 n n n 的数组 a a a。你需要将其重新排列成数组 b b b,判断是否存在一种方案使得 b 1 m o d b 2 m o d … m o d b n ≠ 0 b_1 \bmod b_2 \bmod \dots \bmod b_n \ne 0 b1modb2mod…modbn=0。
样例 #1
样例输入 #1
8
6
1 2 3 4 5 6
5
3 3 3 3 3
3
2 2 3
5
1 1 2 3 7
3
1 2 2
3
1 1 2
6
5 2 10 10 10 2
4
3 6 9 3
样例输出 #1
YES
NO
YES
NO
YES
NO
YES
NO
Note
In the first test case, rearranging the array into b = [ 1 , 2 , 3 , 4 , 5 , 6 ] b = [1, 2, 3, 4, 5, 6] b=[1,2,3,4,5,6] (doing nothing) would result in 1 m o d 2 m o d 3 m o d 4 m o d 5 m o d 6 = 1 1 \bmod 2 \bmod 3 \bmod 4 \bmod 5 \bmod 6 = 1 1mod2mod3mod4mod5mod6=1. Hence it is possible to achieve the goal.
In the second test case, the array b b b must be equal to [ 3 , 3 , 3 , 3 , 3 ] [3, 3, 3, 3, 3] [3,3,3,3,3], which would result in 3 m o d 3 m o d 3 m o d 3 m o d 3 = 0 3 \bmod 3 \bmod 3 \bmod 3 \bmod 3 = 0 3mod3mod3mod3mod3=0. Hence it is impossible to achieve the goal.
In the third test case, rearranging the array into b = [ 3 , 2 , 2 ] b = [3, 2, 2] b=[3,2,2] would result in 3 m o d 2 m o d 2 = 1 3 \bmod 2 \bmod 2 = 1 3mod2mod2=1. Hence it is possible to achieve the goal.
AC代码:
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=998244353;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;
int t;
int n;
int a[N];
int main()
{
cin >> t;
while(t --)
{
cin >> n;
int flag = 0;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
}
sort(a + 1, a + 1 + n);
if(a[1] != a[2]) puts("YES");
else {
for(int i = 2; i <= n; i ++)
{
if(a[i] % a[1] != 0) flag = 1;
}
if(flag) puts("YES");
else puts("NO");
}
}
return 0;
}
标签:10,int,第七期,bmod,Codeforces,929,test,YES,include
From: https://blog.csdn.net/2301_80882026/article/details/136781591