【CodeForces - 569C】Primes or Palindromes? (思维,分析范围,暴力枚举判断)

题干:

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 nrub(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 Afind the maximum n, such that π(n) ≤ A·rub(n).

Input

The input consists of two positive integers pq, the numerator and denominator of the fraction that is the value of A ().

Output

If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).

Examples

Input

1 1

Output

40

Input

1 42

Output

1

Input

6 4

Output

172

题目大意:

定义π(N)=∑(i为素数?1:0),i<=N, rub(N)=∑(i为回文数?1:0),i<=N。A=p/q,求最大的N,使得π(n) ≤ A·rub(n)。

解题报告:

     通过观察单调性(因为显然素数个数增长的快啦,可以打个表判断一下,n随便取个值,然后输出几组数据,就可以看出来,素数个数的增长远远大于回文数的增长,我这有个数据,100W个数,有1000个回文数左右),和p和q给的范围(给你范围的目的就是告诉你,可以打表?),我们知道可以算出一个极限来,可以算出 ,n是20W就足够了,数据量也不大,直接打表暴力。

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 2e6+ 5;
int wei[1005],cnt;
ll su[1000005];
bool isprime[MAX];
ll sum1[MAX],sum2[MAX];//sum1素数,sum2回文数 
void prime() {cnt = 0;memset(isprime,1,sizeof isprime);isprime[0] = isprime[1] =0;for(ll i = 2 ; i<MAX; i++) {if(isprime[i]) {su[++cnt] = i;}for(ll j = 1; i * su[j]< MAX && j <= cnt; j++) {isprime[i * su[j]] = 0;}}
} 
bool fit(int x) {int p = 0;while(x) {wei[++p] = x%10;x/=10;}for(int i = 1; i<=(p+1)/2; i++) {if(wei[i] != wei[p-i+1]) return 0;}return 1;
} 
int main()
{int n;//1000W 中 1W个回文数左右int p,q;scanf("%d%d",&p,&q);prime();for(int i = 1; i<MAX; i++) {sum1[i] = sum1[i-1];if(isprime[i]) sum1[i]++;}for(int i = 1; i<MAX; i++) {sum2[i] = sum2[i-1];if(fit(i)) sum2[i]++;}int ans = -1; for(int i = MAX-1; i>=0; i--) {if(sum1[i] * q <= sum2[i] * p) {ans = i;break;}}if(ans == -1) puts("Palindromic tree is better than splay tree");else printf("%d\n",ans);return 0 ;} 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441635.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux中软件安装使用的命令是,Linux软件安装命令

1.tartar命令用于把多个文件合并于一个档案文件中,并提供分解的合并后的档案文件的功能.它独立于压缩工具,因此可以选择在合并前是否压缩.tar命令的基本用法为:tar[选项]文件名常用的选项包括-c创建一个新的档案文件-t查看档案文件的内容-x分解档案文件的内容-f指定档案文件的名…

linux data文件如何打开,DATA 文件扩展名: 它是什么以及如何打开它?

DATA 问题的来源常见的 DATA 打开问题Microsoft Excel 消失如果您尝试加载 DATA 文件&#xff0c;则会收到 “无法打开 DATA 文件” 等消息。 通常情况下&#xff0c;这意味着 Microsoft Excel 没有安装在 %%os%% 上。 通过双击打开 DATA 的典型路径将不起作用&#xff0c;因为…

【CodeForces - 574D】Bear and Blocks (dp,思维)

题干&#xff1a; Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample. Limak will repeat th…

linux 编译文件mm,Linux编译C++文件,说没有找到头文件,怎么啊?新手,不太会用...

源程序&#xff1a;#include int main (int argc,char**argv){cout<return 0;}终端命令&#xff1a;zhaoweizhaowei-desktop:~$ g -c hello.cpphello.cpp:1:22: error: iostream.h: No such file or directoryhello.cpp: In function ‘int main(int, char**)’:hello.cpp:4…

【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

题干&#xff1a; Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to …

linux下apache配置文件测试,重启 Apache 服务器及测试配置

在 CentOS / RHEL / Fedora Linux 服务器上安装的 Apache 网页服务器程序在系统中的进程名称为 httpd。每次更改 Apache 服务器的配置&#xff0c;不管是 httpd.conf 还是 vhost.conf 或者自己配置的什么 .conf&#xff0c;只要有改动都需要重新加载配置或者重启 httpd 服务才能…

【CodeForces - 574C】Bear and Poker(思维,剪枝,数学)

题干&#xff1a; Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Ea…

linux变量赋值取值,linuxshell编程对变量的赋值

linux shell编程对变量的赋值shell对变量的赋值&#xff0c;所有的变量都是由字符串组成&#xff0c;不需要对变量名预先声明&#xff0c;而且有很多关键字供编程者使用。下面列举例子详细说明。 在终端下建立文件 #vi s2.sh#!/bin/sh#set a variable aa"hello world"…

*【CodeForces - 574A】Bear and Elections (优先队列,水题模拟)

题干&#xff1a; Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th …

stm32linux区别,STM32MPU和OpenSTLinux你了解多少?

早在2019年年初的时候&#xff0c;ST就发布了首款STM32MPU&#xff1a;STM32MP1。 STM32MP1通用微处理器产品系列&#xff0c;系基于混合的 双Arm Cortex-A7核 和 Cortex-M4核架构产品。 一、支持STM32MPU 生态系统熟悉 Cortex-M4 MCU 环境的开发人员能轻松实现他们的目标&…

算法总结 -- 博弈论(PN图)

博弈论&#xff1a;组合博弈 * 必败点(P点) :前一个选手(Previous player)将取胜的位置称为必败点。 * 必胜点(N点) :下一个选手(Next player)将取胜的位置称为必胜点。 * 必败&#xff08;必胜&#xff09;点的属性&#xff1a;* (1) 所有终结点是必败点&#xff08;P点&#…

linux安全模式改文件,嵌入式Linux的安全模式设计 - 嵌入式操作系统 - 电子发烧友网...

本系统的架构如下图&#xff1a;产品所使用的flash总大小为16M。系统包括三大部分&#xff0c;即Bootloader&#xff0c;config, kernel rootfs&#xff1a;另外&#xff0c;/dev/mtdblock/0&#xff0c;在系统中对应整个flash block&#xff0c;即整个16M空间。系统启动时&am…

【POJ - 1661】Help Jimmy(记忆化搜索,dp)

题干&#xff1a; Help Jimmy" 是在下图所示的场景上完成的游戏。 场景中包括多个长度和高度各不相同的平台。地面是最低的平台&#xff0c;高度为零&#xff0c;长度无限。 Jimmy老鼠在时刻0从高于所有平台的某处开始下落&#xff0c;它的下落速度始终为1米/秒。当Jim…

c语言linux消息机制,linux消息机制的过程是什么啊,请赐教

LINUX的安装过程很简单,按照它的提示进行就可以了.重点就是分区那里.通常我们使用双系统,那样我们在LINUX分区的时候不要把WIN分区跟格掉就好,然后要记得分一个SWAP分区,然后根据您的需要进行相应的分区,比如/HOME,/USR,/VAR等等.下面介绍一下具体操作步骤&#xff1a;假定用户…

ACM与Java -- 大整数类的常用函数一览表

BigInteger abs() 此方法返回一个BigInteger&#xff0c;其值是此BigInteger的绝对值。2BigInteger add(BigInteger val) 此方法返回一个BigInteger&#xff0c;其值是(this val).3BigInteger and(BigInteger val) 此方法返回一个BigInteger&#xff0c;其值是 (this & v…

linux虚拟机上安装域名,虚拟机如何安装linux系统

虚拟机如何安装linux系统&#xff1f;安装linux系统首先要在电脑上安装好虚拟机&#xff0c;然后逐步进行linux系统安装。大致介绍下安装的流程。1.首先打开虚拟机软件,点击文件/新建虚拟机&#xff0c;用户可以按照默认选择&#xff0c;然后点击下一步。2.在浏览里&#xff0c…

想打ACM?想刷题?来这些online judge!

原文地址&#xff1a;https://blog.csdn.net/tigerisland45/article/details/52134189

基于arm下的Linux控制,基于ARMuCLinux的网络控制系统设计与实现

引言 随着网络和通信技术的发展&#xff0c;嵌入式系统现已进入高速发展阶段。并在社会各个领域得到了广泛的应用。本文介绍了一种采用ARMuCLinux作为开发平台。实现基于TCP&#xff0f;IP的远程系统监控&#xff0e;从而取代传统单片机来实现数据采集、预处理和通信功能&am…

【qduoj - 1121】小明的贪心题(Dijkstra最短路 + 最短路条数)

题干&#xff1a; 小明的贪心题 描述 小明来到青岛上学已经一年了&#xff0c;他给青岛这座城市画了一张地图。在这个地图上有n个点&#xff0c;小明的起始点为1号点&#xff0c;终点为n号点&#xff0c;并且地图上的所有边都是单向的。小明知道从i号点到j号点的时间花费为w分…

nodejs 监控linux,linuxServerMonitoring

linux服务器监控平台技术&#xff1a;nodejs vue java mongodb springboot linux shelllinux服务器监控项目&#xff0c;前后端分离vuespringbootmongodb&#xff1a;1、启动前台&#xff1a;使用命令&#xff1a;A 先安装nodejs并配置好环境变量B 先控制台cmd命令切换到项目目…