社区讨论

艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹 10pts 求助!

B3929[GESP202312 五级] 小杨的幸运数参与者 3已保存回复 17

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
17 条
当前快照
1 份
快照标识符
@m27ii9c4
此快照首次捕获于
2024/10/13 19:38
去年
此快照最后确认于
2025/11/04 23:55
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
bool hasSquare(int n) {
	int x = sqrt(n);
	return x * x == n;
}
int lucky(int n, int a) {
	if (n < a) 
		while (n++) 
			if (n >= a && hasSquare(n))
				return n;
	if (hasSquare(n)) 
		return -1;
	for (int i = a; i <= n / 2 + 1; i++)
		if (hasSquare(i) && !(n % i)) 
			return -1;
}
int luckying(int n, int a) {
	if (n < a) 
		while (n++) 
			if (n >= a && hasSquare(n))
				return n;
	if (hasSquare(n)) 
		return -1;
	for (int i = a; i <= n / 2 + 1; i++)
		if (hasSquare(i) && !(n % i)) 
			return -1;
	while (n++) 
		if (lucky(n, a) == -1)
			return n;
}
int a, n, x;
int main() {
	cin.tie()->sync_with_stdio(false);
	cin >> a >> n;
	while (n--) {
		cin >> x;
		if(luckying(x, a) == -1)
			cout << "lucky\n";
		else
			cout << luckying(x, a) << '\n';
	}
	return 0;
}
10pts?10pts?

回复

17 条回复,欢迎继续交流。

正在加载回复...