time limit per test3 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!

Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.

Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.

One problem with prime numbers is that there are too many of them. Let’s introduce the following notation: π(n) — the number of primes no larger than n, rub(n) — the number of palindromic numbers no larger than n. Rikhail wants to prove that there are a lot more primes than palindromic ones.

He asked you to solve the following problem: for a given value of the coefficient A find the maximum n, such that π(n) ≤ A·rub(n).

Input

The input consists of two positive integers p, q, the numerator and denominator of the fraction that is the value of A (, ).

Output

If such maximum number exists, then print it. Otherwise, print “Palindromic tree is better than splay tree” (without the quotes).

Examples

input

1 1

output

40

input

1 42

output

1

input

6 4

output

172

【题目链接】:http://codeforces.com/contest/569/problem/C

【题解】



枚举n.最大枚举到150W就可以了;

这个150W的值是根据前n个数的质数/回文数的值来判断的;

当n>=120W左右时这个比值就达到了42;

真的是暴力出奇迹啊。。

判断的时候不能直接用比值。

两边同时乘个q再比较.不然精度不够的。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
int p,q;
int pn,rubn;
double temp; bool bo(string s,int l,int r)
{
if (l >= r) return true;
if (s[l]==s[r])
return bo(s,l+1,r-1);
else
return false;
} bool is_hui(LL x)
{
string s = "";
while (x>0)
{
s+= (x%10)+'0';
x/=10;
}
return bo(s,0,s.size()-1);
} bool is_zhi(LL x)
{
if (x<2) return false;
int ma = sqrt(x);
rep1(i,2,ma)
if ((x%i)==0)
return false;
return true;
} int main()
{
// freopen("F:\\rush.txt","r",stdin);
rei(p);rei(q);
int ans;
int i =1;
while (i)
{
if (is_hui(i))
rubn++;
if (is_zhi(i))
pn++;
//double t = pn*1.0/rubn*1.0;
//cout << t<<endl;
if (q*pn<=p*rubn)
ans = i;
if (i>150e4) break;
i++;
}
printf("%d\n",ans);
return 0;
}

【34.88%】【codeforces 569C】Primes or Palindromes?的更多相关文章

  1. codeforces 569C C. Primes or Palindromes?(素数筛+dp)

    题目链接: C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes in ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【50.88%】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  7. 【codeforces 793D】Presents in Bankopolis

    [题目链接]:http://codeforces.com/contest/793/problem/D [题意] 给你n个点, 这n个点 从左到右1..n依序排; 然后给你m条有向边; 然后让你从中选出 ...

  8. 【codeforces 799D】Field expansion

    [题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; ...

  9. 【22.73%】【codeforces 606D】Lazy Student

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 李笑来~执行力WWH

    什么是秘密 秘密是指只有极少数人知道的实用信息.这个实用信息可以为知道且懂得运用的人获得收益,这个收益可能包括钱.名声和快感. 什么是执行力 执行力=What + Why + How,即WWH 执行力 ...

  2. 关于大数据项目创建时所需setting.xml(博主推荐)

    我目前,收录经常用的是,这两个版本,这个根据博主我本人的经验之谈,最为稳定和合理的. 注意:我的本地路径是在D:/SoftWare/maven/repository,大家自己改为你们自己的即可.   ...

  3. 用vue.js的v-for,v-if,computed写一个分页样式

    在学Vue,总想写个分页,先写了一个样式. 主要看思路: 思路简单,得到总页数,判断总页数,循环. 先判断总页数是否需要分页,总页数==1页就不分了. 再判断总页数<11就不用--. 总页数&g ...

  4. MySQL各个版本的区别

     文章出自:http://blog.sina.com.cn/s/blog_62b37bfe0101he5t.html 感谢作者的分享 MySQL 的官网下载地址:http://www.mysql. ...

  5. BZOJ 3732 Network Kruskal+倍增LCA

    题目大意:给定一个n个点m条边的无向连通图.k次询问两点之间全部路径中最长边的最小值 NOIP2013 货车运输.差点儿就是原题...仅仅只是最小边最大改成了最大边最小.. . 首先看到最大值最小第一 ...

  6. 强连通分量分解 Kosaraju算法 (poj 2186 Popular Cows)

    poj 2186 Popular Cows 题意: 有N头牛, 给出M对关系, 如(1,2)代表1欢迎2, 关系是单向的且能够传递, 即1欢迎2不代表2欢迎1, 可是假设2也欢迎3那么1也欢迎3. 求 ...

  7. 基于Eclipse的Android JNI层測试应用开发过程记录

    前言 本文记录一个Java层与JNI层參数与数据交互的应用程序开发过程.为实现一个功能完整的带Java与JNI的应用程序打下基础. 本文如果读者已搭建好Android的Eclipse与NDK开发环境, ...

  8. Microsoft SQL Server Version List(SQL Server 版本)

    原帖地址 What version of SQL Server do I have? This unofficial build chart lists all of the known Servic ...

  9. webpack4 多页面,多环境配置,逐行解释

    项目需求制作为新的app的分享页,故需要制作多页面应用,那既然app是新的,这边我们也要更新上,经过多方考察(度娘)下,综合了一些他人的优点并结合项目实况产生了此文. 本文为了解释详细,篇幅可能会较长 ...

  10. [转]DOM0,DOM2,DOM3事件处理方式区别

    转 DOM0,DOM2,DOM3事件处理方式区别 2016年07月13日 15:00:29 judyge 阅读数:1457更多 个人分类: js与前端   引子:        文档对象模型是一种与编 ...