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?的更多相关文章

  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. 2) C. Primes or Palindromes? 暴力

    C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...

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

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

  4. CF 568A(Primes or Palindromes?-暴力推断)

    A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...

  5. 【34.88%】【codeforces 569C】Primes or Palindromes?

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

  6. 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是给定范围的,所以 ...

  7. 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( ...

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

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

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

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

随机推荐

  1. 解决双系统(Window10+Ubuntu16.10)下ubuntu安装git时提示软件包git没有可安装候选问题

    选择升级系统: sudo apt-get update 升级之后再输入: sudo apt-get install git 可成功安装.

  2. javascript高级技巧篇(作用域安全、防篡改、惰性载入、节流、自定义事件,拖放)

    安全的类型检测 在任何值上调用Object原生的toString()方法,都会返回一个[object NativeConstructorName]格式字符串.每个类在内部都有一个[[Class]]属性 ...

  3. codechef Sum of Cubes 图论

    正解:图论+数学 解题报告: 先放个传送门QwQ 然后放下题目大意?就说给定简单图,无自环或重边,然后求(∑e[i][j])k,i,j∈S,S为点集的子集 然后因为k的取值只有[1,3],所以这里分类 ...

  4. 【Python爬虫】正则表达式与re模块

    正则表达式与re模块 阅读目录 在线正则表达式测试 常见匹配模式 re.match re.search re.findall re.compile 实战练习 在线正则表达式测试 http://tool ...

  5. caffe编译报错解决

    添加ssd中的一些层之后,编译报错: ../lib/libcaffe.so.1.0.0-rc5:对‘boost::match_results<__gnu_cxx::__normal_iterat ...

  6. 用Eclipse构建Maven项目

    Eclipse中m2eclipse插件的安装 Help>Install New Software Click Add Name: m2e Location: http://download.ec ...

  7. 接口测试工具-Jmeter使用笔记(五:正则表达式提取器)

    (正则表达式提取器是Jmeter关联中的一种)使用场景: 有两个HTTP请求,请求A的返回数据中有一个字段“ABCD”,该字段要作为请求B的入参. 1.添加方式 请求A上右键-->后置处理器-& ...

  8. UnicodeDecodeError异常

    UnicodeDecodeError异常 UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 154: invali ...

  9. Python-Log-note.md

    #LOG - https://www.cnblogs.com/yyds/p/6901864.html - logging - logging模块提供模块级别的函数记录日志 - 包括四大组件 ## 1. ...

  10. 小程序-formdata传参

    项目背景,后端接口要求formData传参: 在util.js文件中封装转化函数,代码如下: const formatTime = date => { const year = date.get ...