能够发现不可能无解,极限情况n不大
#include#include #include #include #include #include #include #include #include using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i =0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}bool is_prime(int x){ if (x==1) return 0; Fork(i,2,sqrt(x)) { if (x%i==0) return 0; } return 1;}const int MAXN =10000000;int P[MAXN],siz=0,b[MAXN]={0};void make_prime(int n){ Fork(i,2,n) { if (!b[i]) { P[++siz]=i; } For(j,siz) { if (P[j]*i>n) break; b[P[j]*i]=1; if (i%P[j]==0) break; } }}bool is_pal(int x){ char s[10]; sprintf(s,"%d",x); int p=0,q=strlen(s)-1; while(p -1;j++,p--) s[j]=s[p]; int x; sscanf(s,"%d",&x); if (x<=n) B[x]=1; for(int j=m;j<=2*m-1;j++) s[j]=s[j+1]; sscanf(s,"%d",&x); if (x<=n) B[x]=1; } }int main(){// freopen("A.in","r",stdin);// freopen(".out","w",stdout); int p,q; cin>>p>>q; make_prime(MAXN-1); make_pal(MAXN-1); int x1=0,x2=0,n=MAXN-1,ans=1,t=1; For(i,n) { if (i==P[t]) x1++,t++; if (B[i]) x2++; if ((ll)(x1)*q<=(ll)(x2)*p) ans=i; } cout<<