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秒的歌曲是事先下载好的) ...
随机推荐
- Azkaban 简介
本文简单介绍一下Azkaban及其特点.azkaban是一个开源的任务调度系统,用于负责任务的调度运行(如数据仓库调度),用以替代linux中的crontab. 一.Azkaban是什么? 1.1 A ...
- Impala与Hive的比较
1. Impala架构 Impala是Cloudera在受到Google的Dremel启发下开发的实时交互SQL大数据查询工具,Impala没有再使用缓慢的Hive+MapReduce批 ...
- centos7 centos-home 磁盘转移至centos-root下
1.查看分区 df -h (centos-home和centos-root每人的名字可能不一样) vgdisplay (查看空闲磁盘大小) 2.备份home分区文件 tar cvf /tmp/home ...
- vue-cli使用
vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目,GitHub地址是:https://github.com/vuejs/vue-cli 一.安 ...
- Python之路----迭代器与生成器
一.迭代器 L=[1,,2,3,4,5,] 取值:索引.循环for 循环for的取值:list列表 dic字典 str字符串 tuple元组 set f=open()句柄 range() enumer ...
- 电脑异常断电,IDEA崩溃
今天电脑突然断电,当时正好开着idea,等了半天无果,只能强行关机重启.重启之后,那么问题来了:重新打开idea报错java.lang.AssertionError:upexpected conten ...
- python的re正则表达式模块
元字符 . * + ? ^ $ { } [ ] - \ . 匹配除了/n之外的任意一个字符 * 匹配*前面的单个字符任意次,即[0,+∞] + 匹配 ...
- 作为从业人员,如果一定要学一门新的编程语言,那么它一定是c++
作为从业人员,如果一定要学一门新的编程语言,那么它一定是c++. 无论各种编程语言排行榜如何变化,什么语言最赚钱,想成为真正的程序员,那么c/c++是必修课,因为几乎所有的底层都是c/c++编写的,各 ...
- JavaScript 实现 标签页 切换效果
JavaScript 实现 标签页 切换效果 版权声明:未经授权,严禁分享! 构建主体界面 HTML 代码 <h1>实现标签页的切换效果</h1> <ul id=&quo ...
- 01: JavaScript实例
1.1 基础 JavaScript 实例 <body> <script type="text/javascript"> document.write(&qu ...