“‘sqrt’在此作用域中尚未声明”是为啥?本地没问题啊
查看原帖
“‘sqrt’在此作用域中尚未声明”是为啥?本地没问题啊
268811
画船听雨楼主2022/1/20 22:49
#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;

bool zhishu(int x) {
	if (x <= 3) return x > 1;
	if (x % 6 != 1 && x % 6 != 5) return false;
	for (int i = 5; i < sqrt(x); i = i + 6) {
		if (x % i == 0 || x % (i + 2) == 0)
			return false;
	}
	return true;
}

int main() {
	int a, b, i, j;
	string str;
	cin >> a >> b;
	for (i = a; i <= b; i++) {
		if (zhishu(i)) {
			stringstream ss;
			ss << i;
			ss >> str;
			if (str.size() == 1)
				cout << str << endl;
			else {
				if (str.size() % 2 == 0) {
					for (j = 0; j < str.size() / 2; j++) {
						if (str[j] != str[str.size() - 1 - j])
							break;
					}
					if (j == str.size() / 2)
					cout << str << endl;
				}
				else {
					for (j = 0; j < str.size() / 2; j++) {
						if (str[j] != str[str.size() - 1 - j])
							break;
					}
					if(j==str.size()/2)
					cout << str << endl;
				}
			}

		}
	}

	return 0;
}
2022/1/20 22:49
加载中...