为啥?
  • 板块学术版
  • 楼主封禁用户
  • 当前回复10
  • 已保存回复10
  • 发布时间2024/7/26 15:29
  • 上次更新2024/7/26 16:26:47
查看原帖
为啥?
1001535
封禁用户楼主2024/7/26 15:29
#include <bits/stdc++.h>
using namespace std;
const int N = 1e8 + 5;
int n, T;
int x;
int vis[N];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> T;
	while (T--) {
// 		f = 0;
		memset(vis, 0, sizeof(vis));
		cin >> n;
        int f = 0;

		for (int i = 1; i <= n; i++) {
			cin >> x;
			int temp = x;
			if (f) {
				continue;
			}
			for (int i = 2; i * i <= x; i++) {
				if (temp < i) break;
				if (!(temp % i)) {
					if (vis[i]) {
						f = 1;
						break;
					}
					while (temp % i == 0)
						temp /= i;
					vis[i]++;
				}
			}
			if (temp > 1) {
				if (vis[temp])
					f = 1;
				vis[temp]++;
			}
		}
		if (x == 1 && n == 1) {
			cout << "Yes\n";
		}
		if (n == 2)
			cout << "Yes\n";
		else if (f)
			cout << "No\n";
		else
			cout << "Yes\n";
	}
	return 0;
}

当中把 for (int i = 2; i * i <= x; i++)

换成 for (int i = 2 ; i <= sqrt(x); i++) 为啥超时?

求大佬解释!

2024/7/26 15:29
加载中...