蒟蒻,3TLE,大佬求助!!!
查看原帖
蒟蒻,3TLE,大佬求助!!!
748239
OIbishop楼主2022/9/22 21:29

RT

#include <bits/stdc++.h>
#define ULL unsigned long long
using namespace std;
ULL o = 1;
inline int read()
{
	int s = 0 , f = 1;
	char c = getchar();
	while (c < '0' || c > '9')
	{
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		s = s * 10 + c - '0';
		c = getchar();
	}
	return s * f;
}

bool qwe(unsigned long long o)
{
    if (o == 1 || o == 0) return 0;
	for (int i = 2; i * i <= o; i++)
	{
		if (o % i == 0) return 0;
	}
	return 1;
}

int main()
{
	int t;
	t = read();
	for (int ii = 1; ii <= t; ii++)
	{
		int a[99999] , b[99999] , n , m;
		o = 1;
		n = read();
		m = read();
		if (n == m) 
		{
			cout << "NO";
			continue;
		}
		for (int i = 1; i <= n; i++) a[i] = read();
		for (int i = 1; i <= m; i++) b[i] = read();
		if (m == 0 || n == 0)
		{
			cout << "NO";
			continue;
		}
		for (int j = 1; j <= n; j++)
		{
			for (int i = 1; i <= m; i++)
			{
				if (a[j] == b[i])
				{
				    a[j] = 1;
				    b[i] = 1;
				    break;
				}
			}
			o *= a[j];
		}
		if (qwe(o) == 1) 
		{
			putchar ('Y');
			putchar ('E');
			putchar ('S');
			cout << "\n";
		}
		else 
		{
			putchar ('N');
			putchar ('O');
			cout << "\n";
		}
	}
	return 0;
}/*
1
5 3
1 1 2 2 3
1 2 2
*/
2022/9/22 21:29
加载中...