这道题居然是一个大暴力。。。

题意:

π(n):小于等于n的数中素数的个数

rub(n) :小于等于n的数中属于回文数的个数

然后给你两个数p,q,当中A=p/q。 然后要你找到对于给定的A。找到使得π(n) ≤ A·rub(n)
最大的n。

(A<=42)

思路:

首先我们能够暴力算出当n为大概150万左右的时候,π(n)大概是 rub(n) 的42倍。

所以我们仅仅须要for到150万左右就好,由于对于后面的式子。肯定能在150万的范围内找到一个n使得这个式子成立的。

并且。我们可以得出由于素数的增长速度肯定是大于回文数的增长速度的,所以我们肯定可以保证这个式子是成立的。

所以。按理说应该不存在impossible的情况。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<math.h>
using namespace std;
#define maxn 2000020
int flag[maxn],num[maxn];
int pal[maxn];
int gcd(int a,int b){
if(b!=0) return gcd(b,a%b);
else return a;
}
void getprime(){
fill(num,num+1+maxn,1);
num[0]=num[1]=0;
int t=0;
for(int i=2;i<=maxn;i++){
if(num[i]){
for(int j=2*i;j<=maxn;j+=i){
num[j]=0;
}
}
num[i]+=num[i-1];
}
}
bool judge(int n){
int t=0;
while(n){
pal[t++]=n%10;
n=n/10;
}
for(int i=0;i<t/2;i++){
if(pal[i]!=pal[t-1-i]) return false;
}
return true;
}
int main(){
getprime();
int m=0,c=0;
int p,q;
scanf("%d%d",&p,&q);
int lmax=-1;
for(int i=1;i<=maxn;i++){
if(judge(i)&&i!=0) c++;
if(q*num[i]<=p*c){
lmax=i;
}
}
if(lmax==-1) printf("Palindromic tree is better than splay tree\n");
else printf("%d\n",lmax);
}

Codeforces Round #315 (Div. 2)——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 Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力

    题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...

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

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

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

  6. Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)

    链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...

  7. Codeforces Round #315 (Div. 2)

    这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题. Problem_A: 题意: 你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的 ...

  8. Codeforces Round #315 (Div. 2B) 569B Inventory 贪心

    题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...

  9. Codeforces Round #315 (Div. 2A) 569A Music (模拟)

    题目:Click here 题意:(据说这个题的题意坑了不少人啊~~~)题目一共给了3个数---- T 表示歌曲的长度(s).S 表示下载了歌曲的S后开始第一次播放(也就是说S秒的歌曲是事先下载好的) ...

随机推荐

  1. [LuoguP4892]GodFly的寻宝之旅 状压DP

    链接 基础状压DP,预处理出sum,按照题意模拟即可 复杂度 \(O(n^22^n)\) #include<bits/stdc++.h> #define REP(i,a,b) for(in ...

  2. ORA-16047: DGID mismatch between destination setting and standby

    主库有报错如下: ORA-16047: DGID mismatch between destination setting and standby 原因:主库参数设置错误,检查下列参数:log_arc ...

  3. Android Studio使用Mob来获取手机验证码的源码

    本文来自:CSDN 感谢作者:qq_35812301(其实就是我的号!) 查看原文:http://blog.csdn.net/qq_35812301/article/details/79150775 ...

  4. Boost解析xml——xml写入

    <?xml version="1.0" encoding="utf-8"?> <Config> <Item name=" ...

  5. easy ui 验证

    $('#IdentityCertificate').validatebox({required:true}); $('#memberName').validatebox({required:true} ...

  6. Jmeter--性能测试工具的搭建

    第一步:Jmeter软件下载第二步:解压下载的Jmeter包到某一盘符下,最好解压到无中文字符目录下,防止乱码问题,以我电脑为例,比如:D:tools第三步:找到解压的文件jmeter.bat,一般在 ...

  7. 【Codeforces Round #433 (Div. 2) C】Planning

    [链接]h在这里写链接 [题意] 让你确定ti,使得∑(ti-i)*gi最小,其中ti∈[k+1..k+n],且每个ti都不能一样. 且ti>=i必须成立. [题解] 分解一下成为∑ti*gi ...

  8. linux下设置密码复杂度限制,怎么设置?

    在linux,设置密码复杂度的方法有几个1. 一个是在/etc/login.defs文件,里面几个选项PASS_MAX_DAYS 90 #密码最长过期天数PASS_MIN_DAYS 80 #密码最小过 ...

  9. Vertx简介

    今天看了一篇很不错的关于Vertx的简介,转载下. 原文链接:http://www.csdn.net/article/2015-12-21/2826533?utm_source=tuicool& ...

  10. sqoop 1.4.4-cdh5.1.2快速入门 分类: C_OHTERS 2015-06-06 11:40 208人阅读 评论(0) 收藏

    一.快速入门 (一)下载安装 1.下载并解压 wget http://archive.cloudera.com/cdh5/cdh/5/sqoop-1.4.4-cdh5.1.2.tar.gz tar - ...