Codeforces Round #315 (Div. 2)——C. Primes or Palindromes?
这道题居然是一个大暴力。。。
题意:
π(n):小于等于n的数中素数的个数
rub(n) :小于等于n的数中属于回文数的个数
然后给你两个数p,q,当中A=p/q。 然后要你找到对于给定的A。找到使得π(n) ≤ A·rub(n)
最大的n。
(A<=42)
思路:
首先我们能够暴力算出当n为大概150万左右的时候,π(n)大概是 rub(n) 的42倍。
所以我们仅仅须要for到150万左右就好,由于对于后面的式子。肯定能在150万的范围内找到一个n使得这个式子成立的。
并且。我们可以得出由于素数的增长速度肯定是大于回文数的增长速度的,所以我们肯定可以保证这个式子是成立的。
所以。按理说应该不存在impossible的情况。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<math.h>
using namespace std;
#define maxn 2000020
int flag[maxn],num[maxn];
int pal[maxn];
int gcd(int a,int b){
if(b!=0) return gcd(b,a%b);
else return a;
}
void getprime(){
fill(num,num+1+maxn,1);
num[0]=num[1]=0;
int t=0;
for(int i=2;i<=maxn;i++){
if(num[i]){
for(int j=2*i;j<=maxn;j+=i){
num[j]=0;
}
}
num[i]+=num[i-1];
}
}
bool judge(int n){
int t=0;
while(n){
pal[t++]=n%10;
n=n/10;
}
for(int i=0;i<t/2;i++){
if(pal[i]!=pal[t-1-i]) return false;
}
return true;
}
int main(){
getprime();
int m=0,c=0;
int p,q;
scanf("%d%d",&p,&q);
int lmax=-1;
for(int i=1;i<=maxn;i++){
if(judge(i)&&i!=0) c++;
if(q*num[i]<=p*c){
lmax=i;
}
}
if(lmax==-1) printf("Palindromic tree is better than splay tree\n");
else printf("%d\n",lmax);
}
Codeforces Round #315 (Div. 2)——C. Primes or Palindromes?的更多相关文章
- 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. 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) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
- 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( ...
- Codeforces Round #589 (Div. 2) C - Primes and Multiplication(数学, 质数)
链接: https://codeforces.com/contest/1228/problem/C 题意: Let's introduce some definitions that will be ...
- 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秒的歌曲是事先下载好的) ...
随机推荐
- 1.5 Upgrading From Previous Versions官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 1.5 Upgrading From Previous Versions 1.5 从 ...
- 借Stunnel工具保护E-mail服务器
借Stunnel工具保护E-mail服务器 650) this.width=650;" onclick='window.open("http://blog.51cto.com/vi ...
- 手动挂接NFS
环境: 单板:s3c2440 内核:Linux-2.6.22.6 U-boot1.16 初始根文件系统Yaffs2 前提条件 1. 开发板上要烧写好文件系统 2. 能正常开机进入Linux系统 3. ...
- 全新linux中通过编译方式安装nginx
先去官网下载linux.tar.gz包 http://nginx.org/en/download.html 传到linxu中 解压tar包 在软件包nginx-1.15.9目录下对NGINX进行配 ...
- Vijos——T1279 Leave-绿光
https://vijos.org/p/1279 背景 期待这一份幸运,和一份冲劲,多么奇妙的际遇…….燕姿在演唱完绿光这首歌后,出给了姿迷一个考题. 北欧有一个传说!人一生中能看见绿光!他就一生都可 ...
- 5lession-path路径相关操作
今天开始接触到了文件目录.路径方面的知识点.记录如下 先看代码 #!/usr/bin/python # -*- coding: utf-8 -*- import os import sys curre ...
- String.Empty,NULL和""的区别
String.Empty,NULL和""的区别 string.Empty就相当于"" 一般用于字符串的初始化 比如: string a; Console.Wri ...
- elementUI upload 对图片的宽高做校验
很开心今天中午没有吃饭!原因是一直没有解决掉一个小问题,于是一直试错,最后看了下源码才有了点头绪,历时四五个小时才解决掉,有点怀疑自己的能力了,所以写下此文,记录一下今天的囧况!一般情况下遇到问题,自 ...
- 1.2 Python基础知识 - 字符编码
计算机中的数据是以二进制方式进行存储的,即只有"0"和"1",二进制是属于数据类型的数据,它只可以和其他进制的数据类型进行转换,但是不能存储其他字符,例如:字母 ...
- stm32关于.o的错误
是因为没有加入官方库的原因,而且编译出错之后不能跳转到那里.