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秒的歌曲是事先下载好的) ...
随机推荐
- spring mvc interceptors
<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <mvc:e ...
- linux常用命令:ifconfig 命令
许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).通常需 ...
- oracle中如何判断blob类型字段是否为空
eg.假如有表T_GA_GRJBXX ,字段zp是blob类型 查询blob非空的记录 SELECT * FROM u_rs_sjgx.T_GA_GRJBXX TB WHERE TB.zp IS n ...
- Jquery 数组与字符串之间的转换
var auth_list = []; $("input[name='auth_list']:checkbox").each(function () { if ($(this).a ...
- bzoj3505 / P3166 [CQOI2014]数三角形
P3166 [CQOI2014]数三角形 前置知识:某两个点$(x_{1},,y_{1}),(x_{2},y_{2})\quad (x_{1}<x_{2},y_{1}<y_{2})$所连成 ...
- web应用下的安全问题以及tomcat/nginx对应解决方法(持续更新、亲测可解决问题)
最近一券商那边扫描反馈了下面几个非业务型安全漏洞,要求解决,如下: XSS 自己写个脚本response的时候对特殊字符进行了处理,或者网上搜下一堆(不要忘了回车.换行). HTML form wit ...
- C++设计模式 之 “对象性能” 模式:Singleton、Flyweight
“对象性能”模式 面向对象很好地解决了“抽象”的问题,但是必不可免地要付出一定的代价.对于通常情况来讲,面向对象的成本大都可以忽略不计.但是某些情况,面向对象所带来的成本必须谨慎处理. 典型模式 # ...
- 基于qml创建最简单的图像处理程序(1)-基于qml创建界面
<基于qml创建最简单的图像处理程序>系列课程及配套代码基于qml创建最简单的图像处理程序(1)-基于qml创建界面http://www.cnblogs.com/jsxyhelu/p/83 ...
- 20145324王嘉澜 《网络对抗》进阶实践之 shellcode注入和Return-to-libc攻击深入
Shellcode注入 •Shellcode实际是一段代码,但却作为数据发送给受攻击服务器,将代码存储到对方的堆栈中,并将堆栈的返回地址利用缓冲区溢出,覆盖成为指向 shellcode的地址 •实验参 ...
- React 回忆录(二)为什么使用 React?
Hi 各位,欢迎来到 React 回忆录!