【34.88%】【codeforces 569C】Primes or Palindromes?
来源:互联网 发布:柔道 空手道知乎 编辑:程序博客网 时间:2024/06/01 19:50
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
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
【题目链接】:http://codeforces.com/contest/569/problem/C
【题解】
枚举n.最大枚举到150W就可以了;
这个150W的值是根据前n个数的质数/回文数的值来判断的;
当n>=120W左右时这个比值就达到了42;
真的是暴力出奇迹啊。。
判断的时候不能直接用比值。
两边同时乘个q再比较.不然精度不够的。
【完整代码】
#include <bits/stdc++.h>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se second#define rei(x) scanf("%d",&x)#define rel(x) scanf("%I64d",&x)typedef pair<int,int> pii;typedef pair<LL,LL> pll;//const int MAXN = x;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);int p,q;int pn,rubn;double temp;bool bo(string s,int l,int r){ if (l >= r) return true; if (s[l]==s[r]) return bo(s,l+1,r-1); else return false;}bool is_hui(LL x){ string s = ""; while (x>0) { s+= (x%10)+'0'; x/=10; } return bo(s,0,s.size()-1);}bool is_zhi(LL x){ if (x<2) return false; int ma = sqrt(x); rep1(i,2,ma) if ((x%i)==0) return false; return true;}int main(){ // freopen("F:\\rush.txt","r",stdin); rei(p);rei(q); int ans; int i =1; while (i) { if (is_hui(i)) rubn++; if (is_zhi(i)) pn++; //double t = pn*1.0/rubn*1.0; //cout << t<<endl; if (q*pn<=p*rubn) ans = i; if (i>150e4) break; i++; } printf("%d\n",ans); return 0;}
- 【34.88%】【codeforces 569C】Primes or Palindromes?
- Codeforces 569C Primes or Palindromes?
- Primes or Palindromes? CodeForces
- C. Primes or Palindromes?-Codeforces Round #315 (Div. 2)
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes?
- Codeforces Round #315 (Div. 2)569C Primes or Palindromes?(预处理)
- CodeForces #315 (div1) A.Primes or Palindromes?
- Codeforces 568A Primes or Palindromes?
- CodeForces 568A Primes or Palindromes?
- 【杂题】CodeforcesRound #315 (Div. 2)569C Primes or Palindromes?
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 素数表 回文数
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? (素数打表 回文数)
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? (打表枚举)
- Codeforces Round #315 (Div. 2)——C. Primes or Palindromes?
- Codeforces Round #315 (Div. 2) C - Primes or Palindromes?(暴力打表)
- Codeforces Round #315 -Primes or Palindromes?(回文&&素数)
- CodeForces 568A. Primes or Palindromes?( 素数 + 回文数 )
- Codeforces 568 A Primes or Palindromes?(求素数个数+判断是否是回文数)
- 开源客户端框架:JavaScript
- 2016广东工业大学新生杯决赛:Problem A: pigofzhou的巧克力棒
- Open Inventor学习资源
- fullpage.js 插件的使用
- 2016年12月7日 课堂笔记
- 【34.88%】【codeforces 569C】Primes or Palindromes?
- EasyPR--一个开源的中文车牌识别系统(转)
- .gitignore 忽略编译等不需要上传的文件
- [Spring]error: org.springframework.web.context.ContextLoaderListener
- 【CSRMesh蓝牙开发】CSRMeshDemo源码分析 -- 启动过程
- redhat7.2配置yum源
- QT5:his application failed to start because it could not find or load the Qt platform plugin "xcb"
- 实现虚拟机linux和主机windows之间的文件互传
- python机器学习库scikit-learn简明教程之:随机森林