This problem is actually a big violence ...
Test instructions
π (n): number of prime numbers less than or equal to n
Rub(n) : number of palindrome numbers in numbers less than or equal to n
Then give you two number p,q, where a=p/q; and then you find for a given a, find that makesπ (N)? ≤?A·Rub(N)the largest n.
(a<=42)
Ideas:
First we can figure out that when N is about 1.5 million,π (N) is probably Rub(n)42 times times as much.
So we just need for the for to 1.5 million or so, because for the back of the formula, it will certainly be in the range of 1.5 million to find a N to make this formula set.
Moreover, we can conclude that the growth rate of primes is certainly greater than that of palindrome numbers, so we will certainly be able to guarantee that this formula is set up.
Therefore, it should be said that there should be no impossible situation.
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include < vector> #include <set> #include <map> #include <queue> #include <math.h>using namespace std;# Define MAXN 2000020int flag[maxn],num[maxn];int pal[maxn];int gcd (int a,int b) {if (b!=0) return gcd (b,a%b); else return A;} void Getprime () {Fill (num,num+1+maxn,1), num[0]=num[1]=0;int t=0;for (int i=2;i<=maxn;i++) {if (Num[i]) {for (int j=2* i;j<=maxn;j+=i) {num[j]=0;}} NUM[I]+=NUM[I-1];}} BOOL judge (int n) {int t=0;while (n) {PAL[T++]=N%10;N=N/10;} for (int i=0;i<t/2;i++) {if (Pal[i]!=pal[t-1-i]) return false;} return true;} int main () {getprime (); int m=0,c=0;int p,q;scanf ("%d%d", &p,&q), int lmax=-1;for (int i=1;i<=maxn;i++) {if ( Judge (i) &&i!=0) c++;if (q*num[i]<=p*c) {lmax=i;}} if (lmax==-1) printf ("palindromic tree is better than splay tree\n"), Else printf ("%d\n", Lmax);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces Round #315 (Div. 2)--c. Primes or palindromes?