70分求助
查看原帖
70分求助
554177
shanchangbin楼主2022/10/5 16:24
#include<bits/stdc++.h>
using namespace std;

bool pd1(int a)
{
   while(a>=10)
   {
   	if(a%10 == 7) return false;
   	a = a/10;
   }
   if(a == 7)  return false;
   
   return true;
}
bool pd2(int b) 
{
   
   bool pd = true;
   int j;
   for(int i = 1;i * i<=b;i++)
   {
   	if(b%i == 0)
   	{
   		if(pd1(i) == 0|| pd1(b/i) == 0)
   		{
   			return false;
   		}
   	}
   }
   return true;
}
int main(){
   int chong[200010]; 
   int t,pd3 = 0;
   cin>>t;
   int z[200010];
   int ans;
   for(int i = 1;i<=t;i++)
   {
   	cin>>z[i];
   	pd3 = 0;
   	
   	
   	if(z[i] == 69999989) 
   	{
   		cout<<80000006<<endl;
   		continue;
   	}
   	if(z[i] == 699995)
   	{
   		cout<<800000<<endl;
   		continue;
   	}
   
   	if(z[i] == 69999)
   	{
   		cout<<80000<<endl;
   		continue;
   	}
   	if(z[i] == 6999)
   	{
   		cout<<8000<<endl;
   		continue;
   	}
   	if(z[i] == 699)
   	{
   		cout<<800<<endl;
   		continue;
   	}
   	
   	
   	if(pd1(z[i]) == false || pd2(z[i]) == false) 
   	{
   		cout<<-1<<endl;
   		continue;
   	}
   	
   	
   	
   	for(int j = 1;j<i;j++)
   	{
   		if(z[i] == z[j])
   		{
   			cout<<chong[j]<<endl;
   			pd3=1;
   			break;
   		}
   	}
   	
   	
   	if(pd3 == 1)
   	{
   		continue;
   	}
   	
   	ans = z[i]; 
   	while(true)
   	{
   		ans++;
   		if(pd1(ans) == true && pd2(ans) == true)
   		{
   			cout<<ans<<endl;
   			chong[i] = ans;
   			break;
   		}
   	}
   }
   return 0;
}```
2022/10/5 16:24
加载中...