题意:求使pi(n)*q<=rub(n)*p成立的最大的n。

先收集所有的质数和回文数。质数好搜集。回文数奇回文就0-9的数字,然后在头尾添加一个数。在x前后加a,就是x*10+a+a*pow(10,2)。偶回文同理。然后不能二分,因为比值不是单调的。

乱码:

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
using namespace std;
const int SZ=1e7+,INF=0x7FFFFFFF;
typedef long long lon; vector<lon> pri,pld;
bool isp[SZ]; void init()
{
memset(isp,,sizeof(isp));
isp[]=isp[]=;
for(lon i=;i*i<SZ;++i)
{
for(lon j=i*i;j<SZ;j+=i)
{
isp[j]=;
}
}
for(lon i=;i<SZ;++i)
{
if(isp[i])
{
pri.push_back(i);
}
}
} lon pow(lon x,lon p,int rbs1,int rbs2)
{
lon res=,ele=x;
for(;p;p>>=)
{
if(p&)res*=ele;
ele=ele*ele;
}
return res;
} void getp(lon x,lon bit)
{
if(bit>)
{
return;
}
lon res;
for(lon i=;i<=;++i)
{
res=;
res=x*;
res+=(bit&)?i*pow((lon),bit+,,):i*pow((lon),bit+,,);
res+=i;
if(i)pld.push_back(res);
getp(res,bit+);
}
} int main()
{
std::ios::sync_with_stdio();
init();
for(lon i=;i<=;++i)
{
if(i)pld.push_back(i*);
getp(i*,);
}
for(lon i=;i<=;++i)
{
if(i)pld.push_back(i);
getp(i,);
}
sort(pld.begin(),pld.end());
// for(int i=0;i<pld.size();++i)
// {
// cout<<pld[i]<<endl;
// }
//cout<<pri.size()<<" "<<pld.size()<<endl;
lon p,q;
cin>>p>>q;
lon res=;
for(lon i=;i<2e6+;++i)
{
lon num1=upper_bound(pri.begin(),pri.end(),i)-pri.begin();
lon num2=upper_bound(pld.begin(),pld.end(),i)-pld.begin();
//if(i<2600&&i>2500)cout<<i<<" "<<num1<<" "<<num2<<endl;
if(num1*q<=num2*p)
{
res=max(res,i);
}
}
cout<<res<<endl;
return ;
}

codeforces 568a//Primes or Palindromes?// Codeforces Round #315 (Div. 1)的更多相关文章

  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. 2) (ABCD题解)

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

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

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

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

  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. Linux其他:环境变量配置

    计算机==>右键==>属性==>高级系统设置==>环境变量==> 系统变量path后面+';python路径名

  2. http://xx.xxx.xxx.xx:8080/把路径设置成http服务访问的形式

    1.官网下载python安装包(eg:python-3.6.3-embed-win32),并解压文件 2.配置环境变量 3.cmd里查看python版本并设置服务路径 4. 访问查看

  3. python 类的私有方法例子

    #coding=utf-8 class Person(object):    id=12    def __init__(self,name):        self.name=name       ...

  4. Zookeeper学习记录(二):使用以及配置

    zookeeper已经介绍了它的原理设计以及实现方式,我们接下来介绍zookeeper的使用方法以及简单配置. 下载 获取Zookeeper的发布包,从Apache下载映像中下载一个最新稳定版本. 单 ...

  5. 将图片文件转化为字节数组字符串,并对其进行Base64编码处理,以及对字节数组字符串进行Base64解码并生成图片

    实际开发中涉及图片上传并且量比较大的时候一般处理方式有三种 1.直接保存到项目中 最老土直接方法,也是最不适用的方法,量大对后期部署很不方便 2.直接保存到指定路径的服务器上.需要时候在获取,这种方式 ...

  6. JSP输出HTML时产生的大量空格和换行的去除方法

    在WEB应用中,如果使用jsp作为view层的显示模板,都会被空格/空换行问题所困扰.     这个问题当年也困扰了我比较长的时间.因为在jsp内使用的EL标签和其他标签时,会产生大量的空格和换行符. ...

  7. SNMP学习笔记之SNMP报文协议详解

    0x00 简介 简单网络管理协议(SNMP)是TCP/IP协议簇的一个应用层协议.在1988年被制定,并被Internet体系结构委员会(IAB)采纳作为一个短期的网络管理解决方案:由于SNMP的简单 ...

  8. label语句、break语句和continue语句

    label语句 可以在代码中添加标签,以便使用.以下是label语句的语法: label:statement 示例: start: for (var i = 0; i < count; i++) ...

  9. Python3基础 str 通过拆分字符串与插入新的内容形成新的字符串

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. jz2440移植QT5.6【学习笔记】【原创】

    平台:jz2440 作者:庄泽彬(欢迎转载,请注明作者) 交叉编译工具:arm-linux-gcc (GCC)4.4.3 linux:linu3.4.2 PC环境:ubuntu18.04 一.修改/o ...