CF1708A Difference Operations 题解

这道题只要想到了思路就很简单啦!

具体思路就是:让 \(i\)\(2\) 一直枚举到 \(n\),假如所有的 \(a_i\) 能整除 \(a_1\),就输出 yes,否则输出 no

思路清晰了,代码就非常简单写了。

代码

// Author: CrazyWolf

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e2 + 5;

int a[maxn];

void Work()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++)
		cin >> a[i];
	for (int i = 2; i <= n; i ++)
	{
		if (a[i] % a[1] != 0)
		{
			cout << "NO\n";
			return ;
		}
	}
	cout << "YES\n";
}

int main()
{
	int t;
	cin >> t;
	while (t --)
	{
		Work();
	}
	return 0;
}
posted @ 2022-07-18 16:18  琉璃之月  阅读(42)  评论(0)    收藏  举报