题目:Click here

题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n)。A=p/q;

分析:由于这个题A是给定范围的,所以可以先暴力求下最大的n满足上式,可以想象下随着n的增大A也在增大(总体正相关,并不是严格递增的),所以二分查找时不行的,所以对给定的A,n是一定存在的。这个题的关键就是快速得到素数表最好在O(n)的时间以内。(杭电15多校的一个题也用到了这个算法点这里查看)

 #include <bits/stdc++.h>
using namespace std;
const int M = +; double p, q;
bool prime[M];
int ans, pri, pal;
void getprime( ) { // 类似筛选法求素数 打表
prime[] = false;
for( int i=; i<M; i++ ) {
if( !prime[i] ) continue;
prime[i] = true;
for( int j=; j*i<M; j++ )
prime[i*j] = false;
}
} bool palindromic( int n ) { // 判断回文数
int fn = ;
int aun = n;
while( aun ) {
fn *= ;
fn += aun%;
aun /= ;
}
return fn == n ;
} int main() {
memset( prime, true, sizeof(prime) );
getprime( );
while( ~scanf("%lf%lf", &p, &q ) ) {
double A = p/q;
pri = pal = ;
for( int i=; i<M; i++ ) {
pri += prime[i];
pal += palindromic(i);
if( pal*p/q >= pri )
ans = i;
}
printf("%d\n", ans );
}
return ;
}

Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力的更多相关文章

  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)——C. Primes or Palindromes?

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

  4. Codeforces Round #315 (Div. 2) (ABCD题解)

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

  5. 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( ...

  6. Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)

    链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...

  7. Codeforces Round #315 (Div. 2)

    这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题. Problem_A: 题意: 你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的 ...

  8. Codeforces Round #316 (Div. 2C) 570C Replacement

    题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...

  9. Codeforces Round #315 (Div. 2B) 569B Inventory 贪心

    题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...

随机推荐

  1. 不直接用NSLog

    公司中不直接使用NSLog,而是利用宏定义自己的打印函数,将该打印函数写在项目的.pch文件中.调试的时候往往用到好多打印,但发布的时候确不需要.(一下是在公司中的一些处理) 自定义NSLog 一,固 ...

  2. Java中Calender引用类型

    某些时候需要使用深拷贝: Calendar startTime = (Calendar) this._paramModel.getStartTime().clone(); 这样对startTime.a ...

  3. Android 手机上安装并运行 Ubuntu 12.04

    ubuntu.sh脚本的原地址变动了,导致下载不了,现在更新了网盘地址.小技巧:遇到一些下载失效的时候可以试一试p2p下载工具(如 easyMule.迅雷等)试一试,说不定有人分享过~* —————— ...

  4. OpenGL: 环境配置和图元的绘制

    前言 距离上一篇博客已经过去一个半月了,这段时间过得确实充实,虽然一大段时间泡在图书馆复习,但至少也能学到点东西.跨年晚和元旦一整天,全身心投入图形学小课设的编程,终于实现了老师要求的所有功能,回想起 ...

  5. 利用console控制台调试php代码

    /** * 控制台输出 * @param $var * @param string $level */ public function console($var,$level = 'debug') { ...

  6. IOS 页面之间的传值(主讲delegate)

    IOS的Delegate,通俗一点说就是页面之间的传值. 总结一下现在知道的IOS页面之间传值的方式有三种 1.使用NSNotification发送通知的传值 主要是通过NSNotificationC ...

  7. Bootstrap 响应式瀑布流 (使用wookmark)

    使用瀑布布局 官方 http://www.wookmark.com/jquery-plugin GitHub https://github.com/GBKS/Wookmark-jQuery  (下载后 ...

  8. 关于LD_DEBUG (转载)

    引用 LD_DEBUGThe dynamic library loader used in linux (part of glibc) has some neat tricks. One of the ...

  9. /export/App/zz/phantomjs-1.9.7-linux-x86_64/bin

    /export/App/zz/phantomjs-1.9.7-linux-x86_64/bin

  10. 【从0開始Tornado建站】群聊

    群聊的前台主要代码: {%block content%} <!--<p class='text-success h3'>測试版本号,每天凌晨4:00清水,enjoy it~~:-)& ...