求助啊,全部WA,answer too short on line 1
查看原帖
求助啊,全部WA,answer too short on line 1
693498
207394848R楼主2022/3/11 19:48
#include<cstdio>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;

bool* p = new bool[100000001];
char* num = new char[100000001];

int main() {
	
	int a, b;
	p[0] = false;
	p[1] = false;
	scanf_s("%d%d", &a, &b);

	for (int i = 2; i <= b; i++)
	{
		if (p[i])
		{
			for (int j = i+i; j <= b; j+=i)
			{
				p[j] = false;
			}
		}
	}
	for (int i = a; i <= b; i++)
	{
		if (p[i])
		{
			int temp = i;
			
			int count = 0;
			bool flag = true;
			while (temp)
			{
				num[count++] = temp % 10+'0';
				temp /= 10;
			}
			for (int j = 0; j <= count/2; j++)
			{
				if (num[j]!=num[count-j-1])
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				printf("%d\n", i);
			}
		}
	}
	return 0;
}
2022/3/11 19:48
加载中...