日韩性视频-久久久蜜桃-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? (思维,分析范围,暴力枚举判断)的全部內容,希望文章能夠幫你解決所遇到的問題。

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