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(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)的更多相关文章
- 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 Round #315 (Div. 2) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
- CF 568A(Primes or Palindromes?-暴力推断)
A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- 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 Round #315 (Div. 2)——C. Primes or Palindromes?
这道题居然是一个大暴力... 题意: π(n):小于等于n的数中素数的个数 rub(n) :小于等于n的数中属于回文数的个数 然后给你两个数p,q,当中A=p/q. 然后要你找到对于给定的A.找到使得 ...
- Codeforces Round #315 (Div. 2)
这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题. Problem_A: 题意: 你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的 ...
- Codeforces Round #315 (Div. 2B) 569B Inventory 贪心
题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...
- Codeforces Round #315 (Div. 2A) 569A Music (模拟)
题目:Click here 题意:(据说这个题的题意坑了不少人啊~~~)题目一共给了3个数---- T 表示歌曲的长度(s).S 表示下载了歌曲的S后开始第一次播放(也就是说S秒的歌曲是事先下载好的) ...
随机推荐
- wonderware historian 10安装配置
安装文件为: 关闭用户控制 配置dcom. 安装.net framework 3.5 安装sql server,打sp1补丁 安装Historain 停止ww服务 安装sp1包 重启机器,启动ww服务 ...
- python 操作 hbase
python 是万能的,当然也可以通过api去操作big database 的hbase了,python是通过thrift去访问操作hbase 以下是在centos7 上安装操作,前提是hbase已经 ...
- echart知识点、常用图形
原文地址:https://www.cnblogs.com/kewenxin/p/9338272.html 本文是自己在项目中需要运用到的echarts图形进行整理,都有完整的代码.echarts原型, ...
- Fine报表权限流程分析记录
Fine报表权限流程分析记录 URL访问三种类型的报表:第一个:BI报表 例如: http://192.25.103.250:37799/WebReport/ReportServer?op=fr_bi ...
- win10 nodejs指定ionic版本安装(npm方式)
步骤1 node-v6.11.3-x64.msi 下载安装node-v6.11.3-x64.msi, 安装完成后利用cmd通过npm安装 ionic cordova cmd npm install - ...
- 20145317彭垚《网络对抗》Exp2 后门原理与实践
20145317彭垚<网络对抗>Exp2 后门原理与实践 基础问题回答 例举你能想到的一个后门进入到你系统中的可能方式? 在网上下载软件的时候,后门很有可能被捆绑在下载的软件当中: 例举你 ...
- C++ 表示一个区间值得方法
C++中不允许这样的写法 85<= score <=100;你要想表示85<=score<=100的话只能这么写score>=85&&score<= ...
- Serv-U FTP服务器安装及使用图解教程
Serv-U,是一种被广泛运用的FTP服务器端软件,支持3x/9x/ME/NT/2K等全Windows系列.可以设定多个FTP服务器.限定登录用户的权限.登录主目录及空间大小等,功能非常完备. 它具有 ...
- Linux slab分配器【转】
本文转载自:https://www.ibm.com/developerworks/cn/linux/l-linux-slab-allocator/ 良好的操作系统性能部分依赖于操作系统有效管理资源的能 ...
- Java8的新特性,二进制序列转十进制数字
package kata_007_二进制序列转十进制int; /** * java8 Lambda表达式转换binary序列->十进制数 */ import java.util.ArrayLis ...