Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力
3 seconds
256 megabytes
standard input
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 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).
The input consists of two positive integers p, q, the numerator and denominator of the fraction that is the value of A (, ).
If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).
1 1
40
1 42
1
6 4
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? 暴力的更多相关文章
- 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 ...
- 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是给定范围的,所以 ...
- Codeforces Round #315 (Div. 2)——C. Primes or Palindromes?
这道题居然是一个大暴力... 题意: π(n):小于等于n的数中素数的个数 rub(n) :小于等于n的数中属于回文数的个数 然后给你两个数p,q,当中A=p/q. 然后要你找到对于给定的A.找到使得 ...
- 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 ...
- Codeforces Round #315 (Div. 2) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
- 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( ...
- Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)
链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...
- Codeforces Round #315 (Div. 2)
这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题. Problem_A: 题意: 你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的 ...
- Codeforces Round #315 (Div. 2B) 569B Inventory 贪心
题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...
随机推荐
- 160722、Javascript函数节流
最近在做网页的时候有个需求,就是浏览器窗口改变的时候需要改一些页面元素大小,于是乎很自然的想到了window的resize事件,于是乎我是这么写的 <!DOCTYPE html> < ...
- Openstack创建镜像
如何创建生产用的Openstack镜像 参考官方文档https://docs.openstack.org/image-guide/centos-image.html 1,创建虚拟机硬盘 qemu-im ...
- JAVA源码之JDK(一)——java.lang.Object
想要深入学习JAVA,还需追本溯源,从源码学起.这是我目前的想法.如今JAVA各种开源框架涌出,很多JAVA程序员都只停留在如何熟练使用的层次.身为其中一员的我深感惭愧,所以要加快学习的脚步,开始研究 ...
- 机器被感染病毒文件zigw的处理流程
1.现象 服务器CPU报警,查看时,已接近100%. 2.查找 使用top查看是哪个进程在占用CPU,此时zigw立刻出现,记录下进程的PID,假如为12345. (1) 如果在不知道程序的路径前,就 ...
- macro-name replacement-text 宏 调试开关可以使用一个宏来实现
C++ 预处理器_w3cschool https://www.w3cschool.cn/cpp/cpp-preprocessor.html C++ 预处理器 预处理器是一些指令,指示编译器在实际编译之 ...
- java容器的线程安全性
参考:https://www.cnblogs.com/yjd_hycf_space/p/7760248.html 线程安全的: Vector HashTable StringBuffer 线程不安全的 ...
- Tickets---hdu1260(简单dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1260 题意是有n个人排队买票,第 i 个人买票所需要的时间是a[i],这个人和 i-1 或者 i+1 ...
- 使用from __future__ import unicode_literals时要注意的问题
add by zhj: 在Python中有些库的接口要求参数必须是str类型字符串,有些接口要求参数必须是unicode类型字符串.对于str类型的字符串,调用len()和遍历时,其实都是以字节为单位 ...
- Android 成功 使用GPS获取当前地理位置(解决getLastKnownLocation 返回 null)
最近遇到一个比较棘手的问题:使用GPS定位无法获取当前的地理位置,即getLastKnownLocation方法始终返回null. 后来一篇博文 getLastKnownLocation()返回n ...
- windows如何安装mysql
参考一下网址,已测试可用 https://www.cnblogs.com/reyinever/p/8551977.html