日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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?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?Afind the maximum?n, such that?π(n)?≤?A·rub(n).

Input

The input consists of two positive integers?p,?q, 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 ;}

?

總結

以上是生活随笔為你收集整理的【CodeForces - 569C】Primes or Palindromes? (思维,分析范围,暴力枚举判断)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 一级黄色a | 不卡av在线免费观看 | 日本高清有码 | 97精品超碰一区二区三区 | chien国产乱露脸对白 | 成人在线免费观看视频 | 亚洲欧美一区二区三区在线 | 国产精品久久久久久久久动漫 | 欧美熟妇精品一区二区蜜桃视频 | 青青草免费在线观看 | 黄色日批视频 | 亚洲午夜久久久久久久国产 | 猛男被粗大男男1069 | 韩国av网 | 三上悠亚ed2k | 久久精品免费电影 | 国产熟妇另类久久久久 | 午夜视频在线免费 | 国产100页| 2一3sex性hd | 国产女主播在线 | 综合亚洲网 | 狠狠狠 | 色校园 | 国产黄大片在线观看画质优化 | 亚洲男人的天堂在线视频 | 欧美韩日国产 | xxxx69国产| 久久久性 | 精品在线99| 国产真人做爰毛片视频直播 | 国产精品精品视频 | 国产成人一区二区三区别 | 免费观看日韩 | 成人影院免费 | 韩国伦理av| 99草在线视频 | 日韩久久久久久 | 乱中年女人伦 | 最新在线视频 | 精品国产乱码久久久久久1区2区 | 成人观看网站 | 女~淫辱の触手3d动漫 | 久久国语 | 中国久久久久 | 加勒比hezyo黑人专区 | 黄色精品视频 | 在线中文字日产幕 | 国产成人av免费观看 | 阿v天堂2014 这里有精品 | 大粗鳮巴久久久久久久久 | 综合伊人 | 精品人妻一区二区三区三区四区 | 最新啪啪网站 | 樱桃国产成人精品视频 | 成人免费xxxxxx视频 | 国产精品久久婷婷 | 中文字幕日韩在线视频 | 欧美综合一区二区三区 | 亲子乱一区二区三区 | 欧美www视频 | 强侵犯の奶水授乳羞羞漫虐 | 色视频在线观看免费 | 河北彩花69xx精品一区 | 美腿丝袜亚洲色图 | 插我一区二区在线观看 | a天堂视频在线观看 | 国产精品av在线播放 | 六月综合 | 超碰伊人久久 | 久久婷五月 | 怡红院成人av | 亚洲精品一品 | 国产真实在线 | 俄罗斯色片| 久久黄色片视频 | 日本天堂在线观看 | 91原视频 | 欧日韩一区二区三区 | 国产乱码一区二区 | 国产成人+综合亚洲+天堂 | 国产欧美日韩精品区一区二污污污 | 国产乡下妇女做爰毛片 | 仙踪林av | 亚洲午夜无码久久 | 国产一区二区片 | 久久偷拍免费视频 | 99综合在线| 黄色av网| 欧美一区二区三区粗大 | 麻豆精品在线视频 | www国产成人 | 亚洲在线视频免费观看 | 999伊人 | 国产极品视频在线观看 | 狠狠做深爱婷婷综合一区 | 九色porny视频| 日韩欧美午夜 | 91香蕉国产在线观看 |