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
Description
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.
Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.
One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(n) — the number of primes no larger than n, rub(n) — the number of palindromic numbers no larger than n. Rikhail wants to prove that there are a lot more primes than palindromic ones.
He asked you to solve the following problem: for a given value of the coefficient A find the maximum n, such that π(n) ≤ A·rub(n).
Input
Output
If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).
Sample Input
1 1
Sample Output
40
HINT
题意
给你p,q,A=p/q
π(n)表示1-n中素数的个数
rub(n)表示1-n中回文数的个数
求最大的n,满足π(n) ≤ A·rub(n).
题解:
CF测评姬很快,1e7直接上暴力就好了
暴力算出极限数据大概是1.5*1e6的样子,所以1e7很稳
代码:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 10050000 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } //************************************************************************************** bool flag[maxn]; int primes[maxn], pi; int pa[maxn]; void GetPrime() {int i, j;pi = 0;memset(flag, false, sizeof(flag));for (i = 2; i < maxn; i++){primes[i]+=primes[i-1];if (!flag[i]){primes[i] ++ ;for (j = i; j < maxn; j += i)flag[j] = true;}} } int check_Pa(int x) {int X=x;int x2=0;while(X){x2*=10;x2+=X%10;X/=10;}return x2==x?1:0; } void GetPa() {for(int i=1;i<maxn;i++){pa[i]+=pa[i-1];if(check_Pa(i))pa[i]++;} } int main() {GetPrime();GetPa();double p,q;cin>>p>>q;double A=p/q;int ans=0;for(int i=1;i<maxn;i++){if(A*pa[i]*1.0>=primes[i]*1.0)ans=i;}if(ans==0)cout<<"Palindromic tree is better than splay tree"<<endl;elsecout<<ans<<endl; }
转载于:https://www.cnblogs.com/qscqesze/p/4719862.html
Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力相关推荐
- 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)
题目传送:Codeforces Round #315 (Div. 2) A. Music 题意较难懂.只是仅仅要推公式就好了 注意到S+(q - 1) * t = q * t; 仅仅须要t等于S就可以 ...
- Codeforces Round #743 (Div. 2) E. Paint 区间dp + 暴力
传送门 文章目录 题意: 思路: 题意: 给你一个有nnn个像素的图像,每个像素都有一个颜色aia_iai,保证每种颜色的图像不会超过202020个.你现在每次可以选择一个颜色,并选择一段连续的像素 ...
- Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)
题目链接:Codeforces Round #271 (Div. 2) C. Captain Marmot 题意:给4行数据,每行2个点.(x,y).(a,b).意思是(x,y)绕(a,b)逆时针旋转 ...
- Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力
A. Borya and Hanabi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/442/p ...
- Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力
D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...
- Codeforces Round #614 (Div. 2) D. Aroma‘s Search 暴力 + 思维
传送门 文章目录 题意: 思路: 题意: 给你x0,y0,ax,ay,bx,byx_0,y_0,a_x,a_y,b_x,b_yx0,y0,ax,ay,bx,by,让后根据[ax∗xi−1+ ...
- Codeforces Round #481 (Div. 3) F. Mentors(排序,暴力,map记忆化)
题目 题意: 如果一个程序员比另一个程序员的能力值高,而且这两个程序员不在争吵状态,则能力值较高的程序员可以成为另一个程序员的老师,求每个程序员能成为多少其他程序员的老师. 思路: 先啥都不管,结构体 ...
- Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...
最新文章
- Google首席科学家Peyman 《计算成像去噪进展》斯坦福演讲报告,附视频与Slides
- 第四讲:debugging simulation mismatches
- problem k: 查找某一个数_quot;细节魔鬼quot; 二分查找
- C++学习之路 | PTA乙级—— 1029 旧键盘 (20 分)(精简)
- win7 ie11版本安装报此更新不适用于计算机问题
- 基地保留节目--塔防游戏
- 直播客户端和浏览器使用桌面共享时出现黑屏等问题
- linux sftp连接报错:JSchException: Algorithm negotiation fail问题的解决方法
- 一文读懂什么是数据产品交易
- Android软件自动更新升级(自动下载安装新版本)
- Unity动画系统详解1:在Unity中如何制作动画?
- android漂亮的dialog,一个好看的Android AlertDialog
- 无损音乐下载器 MusicTools单文件免安装-v1.9.3.1
- 求无向图的连通分量或有向图的强连通分量—tarjan()ccf高速公路
- Vert.x核心模块 访问文件系统(十三)
- 英语读音(三)---印度英语发音特点 / Characteristic pronounciation of India Englisth
- Acrel-5000能耗管理系统在武清体育中心项目的应用-安科瑞耿敏花
- 用 openssl 生成数字证书
- 计算机功能转动怎么设定,“怎么调节电脑风扇转速”的解决方案
- 读书笔记:精益数据分析 第17-20章
热门文章
- 安全策略已传播,但有警告信息。0x534:帐户名与安全标识间无任何映射完成
- 面试题40. 最小的k个数
- 关于Python你必须知道的常识
- python网络爬虫的流程图_基于Python的网络爬虫的设计与实现
- Compound创始人:Compound链要成为一个单一全球流动性网络
- SAP License:第三只眼看财务-快速编制现金流量
- 小白入职AI数据工程师
- 惊呆~从风控的多头策略能了解到的行业信息还真不少
- jenkinsapi操作Jenkins,提示:No valid crumb was included in the request
- sax 解析 xml