0分,但不知道那错了,结果都是对的
查看原帖
0分,但不知道那错了,结果都是对的
1152158
Code_Rime楼主2024/8/8 08:47
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int tmp[n],m = 0 ;
	bool a = 1;
	for(int i = 11; i <= n;i++)//所有质数集合 
	{
		for(int j = 2;j <= sqrt(i) ;j++)
		{
			if(i % j == 0)
			{a = 0;break;}
		}
		if(a)
		{
			tmp[m] = i;
			m++;	
		}
		a=1;
	}
	int ans = 1;
	
	if( n <= 100)cout << "1";
	else
	{	for(int i = 21 ;i <= m;i++)
		{if(tmp[i] / 1000 != 0)//四位数
		 {
		 	if( ( tmp[i] / 1000 == tmp[i] % 10 ) && ( ( tmp[i] % 100) / 100 == (tmp[i] % 100) / 10 ) )ans++; 
		 }
		 else//三位数
		 {
		 	if(tmp[i] / 100 == tmp[i] % 10)ans++;
		  } 
		}
		  cout << ans;
	}
	
	return 0;
 } 
2024/8/8 08:47
加载中...