http://codeforces.com/contest/569/problem/C
π(n) — the number of primes no larger than n,
rub(n) — the number of palindromic numbers no larger than n.
for a given value of the coefficient A find the maximum n, such that π(n) ≤ A·rub(n).
A (, ).
没想到先观察一下数据,,,发现最大的A是42,大概n到1200000后 n再大,就会有π(n) >A·rub(n).
因此只要暴力做到120W就好了
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
const int maxn=1200005;
int ok(int x)<span style="white-space:pre"> </span>//判断回文
{
int ret=x;
int j=0;
while(x)
{
j=j*10+x%10;
x/=10;
}
if (j==ret)
return 1;
return 0;
}
int p[maxn+5]; <span style="white-space:pre"> </span>//n之前素数个数
int q[maxn+5];<span style="white-space:pre"> </span>//n之前回文数个数
bool f[maxn+5];
int main()
{
// cout<<ok(212)<<endl;
// return 0;
__int64 i,j;
f[1]=true;
for (i=2;i<=maxn;i++)
{
if (f[i]==false)
{
for (j=i*i;j<=maxn;j=j+i)
{
f[j]=true;
}
}
}
for (i=1;i<=maxn;i++)
{
if (f[i]==false)
p[i]=p[i-1]+1;
else
p[i]=p[i-1];
}
for (i=1;i<=maxn;i++)
{
if (ok(i))
q[i]=q[i-1]+1;
else
q[i]=q[i-1];
}
int a,b;
cin>>a>>b;
for (i=maxn;i>=0;i--)
{
if (p[i]*b<=q[i]*a)
{
printf("%d\n",i);
return 0;
}
}
return 0;
}