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

题意:

π(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. thinkphp杂项功能(主干)

    thinkphp杂项功能(主干) 一.总结 1.杂项功能:杂项里面我需要有点印象的是五个:缓存,多语言,图像处理,文件处理,单元测试 二.thinkphp杂项功能(主干) thinkphp扩展杂项功能 ...

  2. 基于Linux系统WINE虚拟机技术的研究

    650) this.width=650;" onclick="window.open("http://blog.51cto.com/viewpic.php?refimg= ...

  3. golang beego cache

    package main import ( "fmt" "github.com/astaxie/beego/cache" "time" ) ...

  4. vue中watch函数的用法

    vue中watch函数: 不仅可以判断路由变化(上篇博客有介绍),还可以判断数据的变化 (1):首先写watch函数 (2):在data里定义值 (3):在methods里写方法 (4):使用值

  5. Vijos——T 1629 八

    https://vijos.org/p/1629 描述 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的还是8用二进制表示是1000.怎么样,有趣吧.当然题目和这些都没有关系. 某个 ...

  6. 洛谷 P2655 2038年问题

    P2655 2038年问题 题目描述 网络时代,机会与危机共存.“千年虫”解决之后,会不会有新的“虫”出现?回答是肯定的,“2038年”就是一个新的关卡. 也许大家都已经知道计算机的2000年问题是什 ...

  7. ProgressBar-style属性分析

    首先我们看下framework下关于进度条的style定义,如下 <style name="Widget.ProgressBar"> <item name=&qu ...

  8. 纯C++实现的HTTP请求封装(POST/GET)

    纯C++实现的HTTP请求(POST/GET),支持windows和linux, 进行简单的封装, 方便调用.实现如下: #include "HttpConnect.h" #ifd ...

  9. 10. ZooKeeper之搭建伪集群模式。

    转自:https://blog.csdn.net/en_joker/article/details/78673456 在集群和单机两种模式下,我们基本完成了分别针对生产环境和开发环境ZooKeeper ...

  10. BZOJ 4555 [Tjoi2016&Heoi2016]求和 (多项式求逆)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4555 题目大意: 给定 \(S(n,m)\) 表示第二类斯特林数,定义函数 \(f(n ...