C. Primes or Palindromes?
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 nrub(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 pq, 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
题意:不大于n的素数的个数<=A*不大于n的回文数的个数;求最大的n
思路:暴力;
#include<bits/stdc++.h>
using namespace std;
int a[];
int check(int x)
{
int ji=;
while(x)
{
a[ji++]=x%;
x/=;
}
for(int i=;i<ji/;i++)
{
if(a[i]!=a[ji--i])
return ;
}
return ;
}
int prime(int n)
{
if(n<=)
return ;
if(n==)
return ;
if(n%==)
return ;
int k, upperBound=n/;
for(k=; k<=upperBound; k+=)
{
upperBound=n/k;
if(n%k==)
return ;
}
return ;
}
#define ll __int64
const int N=2e6+;
ll p[N],h[N];
int main()
{
for(ll i=;i<=;i++)
{
p[i]=p[i-];
h[i]=h[i-];
if(prime(i))
p[i]++;
if(check(i))
h[i]++;
}
ll u,v;
scanf("%I64d%I64d",&u,&v);
for(int i=;i>;i--)
if(v*p[i]<=u*h[i])
{
printf("%d\n",i);
return ;
}
printf("Palindromic tree is better than splay tree\n");
return ;
}

Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力的更多相关文章

  1. Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力

    A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 ...

  2. Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力

    题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...

  3. Codeforces Round #315 (Div. 2)——C. Primes or Palindromes?

    这道题居然是一个大暴力... 题意: π(n):小于等于n的数中素数的个数 rub(n) :小于等于n的数中属于回文数的个数 然后给你两个数p,q,当中A=p/q. 然后要你找到对于给定的A.找到使得 ...

  4. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  5. Codeforces Round #315 (Div. 2) (ABCD题解)

    比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...

  6. codeforces 568a//Primes or Palindromes?// Codeforces Round #315 (Div. 1)

    题意:求使pi(n)*q<=rub(n)*p成立的最大的n. 先收集所有的质数和回文数.质数好搜集.回文数奇回文就0-9的数字,然后在头尾添加一个数.在x前后加a,就是x*10+a+a*pow( ...

  7. Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)

    链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...

  8. Codeforces Round #315 (Div. 2)

    这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题. Problem_A: 题意: 你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的 ...

  9. Codeforces Round #315 (Div. 2B) 569B Inventory 贪心

    题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...

随机推荐

  1. jQuery.each(object, [callback])数组对象操作--jQuery 对象访问 $().each(callback)

    jQuery.each(object, [callback]) 通用例遍方法,可用于例遍对象和数组. 不同于例遍 jQuery 对象的 $().each() 方法,此方法可用于例遍任何对象.回调函数拥 ...

  2. 1.java中Comparor与Comparable的问题

    1.Comparator中compare()与Comparable中compareTo()方法的区别 Treeset集合创建对象后, A:如果是空构造,即TreeSet<Student> ...

  3. python macos scrapy ,gevent module

    easy_install pip pip install scrapy pip install ipython ImportError: No module named items https://g ...

  4. Java 运行环境介绍

    Java 语言特点: 跨平台性: 一次编译,到处运行.即不受操作系统限制,编译一次,可以在多个平台运行.而这个优势得益于 JVM(Java Virtual Machine, 即Java 虚拟机). 两 ...

  5. LinkedList基本用法

    https://blog.csdn.net/i_lovefish/article/details/8042883

  6. selectedIndex返回被选中的option的index.

    / <label for="city">城市</label> <select id="city" name="schoo ...

  7. df: `/root/.gvfs': Permission denied

    在使用oracle账户检查本地磁盘情况时,总是出现df: `/root/.gvfs': Permission denied信息提示. [oracle@rac1 ~]$ df -h Filesystem ...

  8. .net截取字符串

    string s=abcdeabcdeabcdestring[] sArray1=s.Split(new char[3]{c,d,e}) ;foreach(string i in sArray1)Co ...

  9. Python-Cpython解释器支持的进程与线程

    一.Python并发编程之多进程 1. multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在pyt ...

  10. beego——模板语法

    一.基本语法 go统一使用{{和}}作为左右标签,没有其它的标签符号. 使用"."来访问当前位置的上下文,使用"$"来引用当前模板根级的上下文,使用$var来访 ...