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秒的歌曲是事先下载好的) ...
随机推荐
- c#的中英文混合字符串截取 public static string SubString(string inputString, int byteLength)
/// <summary> /// c#的中英文混合字符串截取(区分中英文) /// </summary> /// <param ...
- HDU——T 3579 Hello Kiki
http://acm.hdu.edu.cn/showproblem.php?pid=3579 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- mysql新加入用户与删除用户详细操作命令
方法1 :使用mysql root(root权限)用户登陆直接赋权也能够创建用户 /usr/bin/mysqladmin -u root password 123456 mysql -uroot -p ...
- [Redux] Understand Redux Higher Order Reducers
Higher Order Reducers are simple reducer factories, that take a reducer as an argument and return a ...
- Elasticsearch和MongoDB
Elasticsearch和MongoDB分片及高可用对比 本文旨在对比Elasticsearch和MongoDB高可用和分片的实现机制. Elasticsearch ES天生就是分布式的,那她又是如 ...
- 使用Spring框架的好处
转自:https://www.cnblogs.com/hoobey/p/6032506.html 在SSH框假中spring充当了管理容器的角色.我们都知道Hibernate用来做持久层,因为它将JD ...
- 每日技术总结:fly.js,个位数前补零等
01.FLY.JS 文档:https://wendux.github.io/dist/#/doc/flyio/readme 02.微信小程序组件——input属性之cursor-spacing 属性 ...
- Python 极简教程(六)运算符
运算符,我们日常生活中使用的加减乘除,都是运算符的一种.当然这种一般我们称为算术运算符,用于处理数字运算的. 但是在计算机语言中,还有很多的运算符.用于处理不用的情况. 主要有以下几类: 算术运算符 ...
- [D3] Create DOM Elements with D3 v4
Change is good, but creating from scratch is even better. This lesson shows you how to create DOM el ...
- Maven 使用Eclipse构建Maven的SpringMVC项目
首先Eclipse需要安装Maven的插件,地址:http://m2eclipse.sonatype.org/sites/m2e. 用MyEclipse安装Maven插件,建出的Maven项目有些问题 ...