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: ...
随机推荐
- 1_02 Vue Slot
slot 插槽 插槽内容 const component ={ template: ` <div> <slot></slot> </div> ` } n ...
- VS2013 opencv配置
有三个地方需要配置,在配置之前首先要将platform配置好,下面的例子是x64 Release的“ 然后需要将include.lib的路径配置好 然后将dll拷贝至编译生成的Release文件夹中即 ...
- 【Mock】mock-server 环境搭建
前言 mock 除了用在单元测试过程中,还有一个用途,当前端开发在开发页面的时候,需要服务端提供 API 接口 此时服务端没开发完成,或者说没搭建测试环境,这个时候前端开发会自己 mock一个 api ...
- linux 查看系统负载:uptime
uptime命令用于查看系统负载,跟 w 命令的输出内容一致 [root@mysql ~]# uptime :: up days, :, user, load average: 1.12, 0.97, ...
- mysql跨库复制: replicate_wild_do_table和replicate-wild-ignore-table
使用replicate_do_db和replicate_ignore_db时有一个隐患,跨库更新时会出错. 如设置 replicate_do_db=testuse mysql;update test. ...
- wx:Textctrl
import wx class Mywin(wx.Frame): def __init__(self, parent, title): super(Mywin, self).__init__(pare ...
- 关于vue中eslint规范报错问题
/* global _ */这样 页面_就不会报错了
- 实时Cartographer测试(1) - rplidar
1.rplidar实时测试 参考文献:http://www.cnblogs.com/liangyf0312/p/8028441.html 修改USB转串口权限 yhexie@ubuntu:~$ cd ...
- spring boot 启动类一定要放置到包的根目录下,也就是和所有包含java文件的包在同一级目录。如果不放置在根目录下,将会提示 no mybatis mapper was found
spring boot 启动类一定要放置到包的根目录下,也就是和所有包含java文件的包在同一级目录.将会将同一目录下的包扫描成bean. 如果不放置在根目录下,将会提示 no mybatis map ...
- mybatis 调用oracle存储过程如何返回out参数值
调试了半天,其实整体用map传入传出也挺简单, 主要是调用存储过程 select标签里平时习惯不写 statementType="CALLABLE",调用没有out参数时也能正常用 ...