求答
  • 板块灌水区
  • 楼主Pollococido
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/7/9 17:14
  • 上次更新2024/7/9 18:55:33
查看原帖
求答
919410
Pollococido楼主2024/7/9 17:14

题目

好像身边的人都用的筛法,我用的原始方法。是这种方法太拉了吗?

附史前算法

#include <bits/stdc++.h>
using namespace std;
int t, n;

int main() {
	cin >> t;
	int cnt;
	while (t--) {
		cin >> n;
		cnt = 0;
		for (int i = 2; i * i <= n; i++) {
			if (n % i != 0) continue;
			cnt++;
			while (n % i == 0) {
				n /= i;
			}
		}
		if (n > 1) cnt++;
		if (cnt == 2) cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}
2024/7/9 17:14
加载中...