C. Primes or Palindromes?
prime numbers non greater than n is about
.
We can also found the amount of palindrome numbers with fixed length k — it is about
which is
.
#include <iostream>
#include <cstdio>
#include <string.h>
#include <cmath>
using namespace std;
const int maxn=;
typedef long long LL;
int numPrime[maxn],numpalindrome[maxn];
void sieve()
{
int na=*;
int m=sqrt(na+);
for(LL i=; i<=m; i++)if(numPrime[i]){
for(LL j=i*i; j<=na; j+=i) numPrime[j]=;
} }
int a[];
int jud(int n)
{
int t=n,m=;
while(t)
m=m*+t%,t/=;
return n==m;
}
int main()
{
for(int i=; i<maxn; i++)numPrime[i]=;
sieve();
for(int i=; i<maxn; i++)numPrime[i]+=numPrime[i-];
for(int i=; i<maxn; i++)numpalindrome[i]+=jud(i)+numpalindrome[i-];
int p,q;
while(scanf("%d%d",&p,&q)==)
{
int ans=-;
for(int i=; i<=; i++)
if(numPrime[i]*q<=numpalindrome[i]*p)ans=i;
if(ans==-) puts("Palindromic tree is better than splay tree");
else printf("%d\n",ans);
}
return ;
}
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. 2) C. Primes or Palindromes? 暴力
C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- codeforces 569C C. Primes or Palindromes?(素数筛+dp)
题目链接: C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes in ...
- CF 568A(Primes or Palindromes?-暴力推断)
A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- 【34.88%】【codeforces 569C】Primes or Palindromes?
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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 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 #315 (Div. 2)——C. Primes or Palindromes?
这道题居然是一个大暴力... 题意: π(n):小于等于n的数中素数的个数 rub(n) :小于等于n的数中属于回文数的个数 然后给你两个数p,q,当中A=p/q. 然后要你找到对于给定的A.找到使得 ...
- Codeforces Round #315 (Div. 2) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
随机推荐
- linux查内存操作:cat /proc/meminfo
https://www.cnblogs.com/zhuiluoyu/p/6154898.html cat /proc/meminfo
- LeetCode 706 Design HashMap 解题报告
题目要求 Design a HashMap without using any built-in hash table libraries. To be specific, your design s ...
- opencv图片拼接报错cv::Stitcher::ERR_NEED_MORE_IMGS (1)
#include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "o ...
- python中的一些用法总结
用python写了一个测试Demo,其中涉及到一些常用的用法,现在记录在这里,方便后续查阅: 1 python中全局变量的使用: 引用全局变量,不需要golbal声明,修改全局变量,需要使用globa ...
- SOCKS5 协议解析
代理 根据 HTTP 1.1 的定义,proxy 是: An intermediary program which acts as both a server and a client for the ...
- 深入SQL Server优化【推荐】
深入sql server优化,MSSQL优化,T-SQL优化,查询优化 十步优化SQL Server 中的数据访问故事开篇:你和你的团队经过不懈努力,终于使网站成功上线,刚开始时,注册用户较少,网站性 ...
- golang fmt格式“占位符”
# 定义示例类型和变量 type Human struct { Name string } var people = Human{Name:"zhangsan"} 普通占位符 占位 ...
- abap form格式的异常处理
1: form 中有异常时,需要用 raising 将异常抛出. *&------------------------------------------------------------- ...
- Py中map与np.rival学习
转自:廖雪峰网站 1.map/reduce map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回. 举例说明 ...
- 【RPC】综述
RPC定义 RPC(Remote Procedure Call)全称远程过程调用,它指的是通过网络,我们可以实现客户端调用远程服务端的函数并得到返回结果.这个过程就像在本地电脑上运行该函数一样,只不过 ...