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秒的歌曲是事先下载好的) ...
随机推荐
- 护眼:我的DIY电脑护眼妙招
每天对着电脑,埋头敲代码,一段时间之后.总是觉得眼睛很涩很难受,所以找到一些对抗的视疲劳的方法.不用花费任何钱,可以让眼睛享受地看着我们的屏幕,方法很简单,过来看看(小伎俩,大牛勿笑~) 一.WIN7 ...
- SQLServer 进阶记录式学习
1.强制类型转换 nvarchar->decimal ) , , ) SET @i = '1083.589' SET @num = @i SELECT @num , )) SELECT @nu ...
- 基于Spring Cloud的微服务落地
微服务架构模式的核心在于如何识别服务的边界,设计出合理的微服务.但如果要将微服务架构运用到生产项目上,并且能够发挥该架构模式的重要作用,则需要微服务框架的支持. 在Java生态圈,目前使用较多的微服务 ...
- 为自己的网站添加Markdown功能 markedjs
Markdown几个简单的标记可以实现轻量级的代替Word方案 不多说,引入开源库js https://github.com/chjj/marked使用方式简单,如下实例代码: <!DOCTYP ...
- 20145222何志威《网络对抗》- Web安全基础实践
20145322何志威<网络对抗>Exp9 Web安全基础实践 基础问题回答 1.SQL注入原理,如何防御 SQL注入 就是通过把SQL命令插入到"Web表单递交"或& ...
- poj 2773 Happy 2006 - 二分答案 - 容斥原理
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11161 Accepted: 3893 Description Two ...
- android 通过webview调起支付宝app支付
网站学习:http://blog.csdn.net/zhuyu19911016520/article/details/71763900
- C# 给某个方法设定执行超时时间
ManualResetEvent.WaitOne 方法 https://msdn.microsoft.com/en-us/library/system.threading.manualreseteve ...
- 51nod 1266 蚂蚁
蚂蚁这道题 就是 不管两只蚂蚁相撞 他们会朝自己的反方向走 不过可以这么想 有蚂蚁1 和 蚂蚁2 并且相向而行 如果撞了以后 蚂蚁1和蚂蚁2 就往回走 ,这里可以理解成蚂蚁1,蚂蚁2 继续 ...
- v-pre原样输出&&v-once只加载一次
html <div id="app"> <div v-pre>{{message1}}</div><!--原样输出--> <b ...