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. python运算符,数据类型,数据类型操作,三目运算,深浅拷贝

    算数运算符: Py2中精确除法需要导入:from __future__ import division,(符由特  ,将来的.滴未省,除法) py3不需要导入 赋值运算符: 比较运算符: 成员运算符: ...

  2. private static final Logger logger= LoggerFactory.getLogger(WhMainBusi.class);

    LoggerFactory.getLogger(WhMainBusi.class):指定类初始化日志对象,在日志输出的时候,将会打印日志信息所在的类.如: logger.info("日志信息 ...

  3. vue-router重新定向、redirect与alias区别

    redirect app.vue <router-link to="/goParams/918/i like vue">goParams</router-link ...

  4. ITouch在xcode下提示‘No such file or directory, at ‘/SourceCache/DVTi...'

    版权声明:本文为博主原创文章,转载或又一次发表请先与我联系. https://blog.csdn.net/jonahzheng/article/details/37692733       用一个台老 ...

  5. Python3学习之路~4.3 装饰器

    定义:本质是函数,装饰其他函数就是为其他函数添加附加功能. 原则: 不能修改被装饰函数的源代码 不能修改被装饰函数的调用方式 实现装饰器知识储备: 函数即“变量” 高阶函数 把一个函数名当做实参传递给 ...

  6. 并发编程---线程queue---进程池线程池---异部调用(回调机制)

    线程 队列:先进先出 堆栈:后进先出 优先级:数字越小优先级越大,越先输出 import queue q = queue.Queue(3) # 先进先出-->队列 q.put('first') ...

  7. 【剑指offer】把数组排成最小的数

    一.题目: 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. 二.思路: ...

  8. echart图表

    http://echarts.baidu.com/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B%20ECharts

  9. cnpm与npm的区别

    原文地址:https://blog.csdn.net/chi1130/article/details/72773278 npm介绍 说明:npm(node package manager)是nodej ...

  10. maven install安装工程

    在一个项目中,想要运行一个子工程,要先把它的依赖工程导入到maven中. 右键依赖工程--run as--maven install.