40分wa求助,时间复杂度超了
查看原帖
40分wa求助,时间复杂度超了
563371
Librety楼主2024/3/28 21:57
#include<bits/stdc++.h>
using namespace std;
int m,n,k;
bool ok(int x)
{
	if(x==1) return false;
	for(int i=2;i*i<=x;i++)
		if(x%i==0) return false;
	return true;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin>>m>>n;
 	for(int i=m;i<=n;i++)
 	{
 		k=i;
		if(ok(k)) 
		{
			while(k>0)
			{
				k=(k-k%10)/10;
				if(ok(k) && k%10==k)
				{
					cout<<i<<endl;
					break;
				}
				else break;
			}
		}
		else continue; 	
	}
	return 0;
}

2024/3/28 21:57
加载中...