CodeForces #315 (div1) A.Primes or Palindromes?
来源:互联网 发布:apache ddos ip 大量 编辑:程序博客网 时间:2024/06/06 01:16
题目大意:
求出最大的n,使得小于等于n的素数的个数<A*小于等于n的回文数的个数。
解题思路:
显而易见一定有答案。
因为A的值很小,而且回文数的个数很少,所以素数打表暴力统计,回文数暴力判断。
n的最大值大概是130w的样子,倒着枚举就可以了。
#include <bits/stdc++.h>#define LL long longusing namespace std;const int N=8000005, mx=8000000;bool np[N];int p[N],pcnt,sum[N];inline int get(int x) {int y=0;for(int t=x;t;t/=10) {(y*=10)+=t%10;}return x==y;}void init() {for(int i=2;i<=mx;++i) {if(!np[i]) {p[pcnt++]=i;sum[i]=1;}for(int j=0; j<pcnt; ++j) {LL t=(LL)p[j]*i;if(t>mx) {break;}np[t]=1;if(i%p[j]==0) {break;}}}for(int i=2;i<=mx;++i) {sum[i]+=sum[i-1];}p[0]=0;for(int i=1;i<=mx;++i) {p[i]=p[i-1]+get(i);}}int main() {int P, q;scanf("%d%d",&P,&q);init();for(int i=mx;i>=1;--i) {if((LL)q*sum[i]<=(LL)P*p[i]) {printf("%d\n",i);return 0;}}puts("Palindromic tree is better than splay tree");return 0;}
0 0
- CodeForces #315 (div1) A.Primes or Palindromes?
- Codeforces 568A Primes or Palindromes?
- CodeForces 568A Primes or Palindromes?
- Primes or Palindromes? CodeForces
- CodeForces 568A. Primes or Palindromes?( 素数 + 回文数 )
- C. Primes or Palindromes?-Codeforces Round #315 (Div. 2)
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes?
- Codeforces Round #315 -Primes or Palindromes?(回文&&素数)
- Codeforces 569C Primes or Palindromes?
- 【34.88%】【codeforces 569C】Primes or Palindromes?
- codeforce 568A Primes or Palindromes?
- codeforces 568A A. Primes or Palindromes?(打表+暴力枚举)
- Codeforces 568 A Primes or Palindromes?(求素数个数+判断是否是回文数)
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 素数表 回文数
- Codeforces Round #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?
- JDK容器 Vector源码剖析
- 【101-Symmetric Tree(对称树)】
- 数据库事务总结
- eclipseRCP深入浅出(学习总结)2015.08.11
- POJ 1741 Tree(树分治|ltc男人八题)
- CodeForces #315 (div1) A.Primes or Palindromes?
- SpringMVC+KindEditor在线编辑器之文件上传
- 用信号量和Posix线程操作来实现双线程高速下载
- mysql存储过程
- 《现代操作系统》精读与思考笔记 第八章 多处理机系统 第九章 安全
- 黑马程序员Java笔记——初识Java
- 黑马程序员——面向对象(下)— 重写、多态、抽象、接口
- 循环 实例
- 黑马程序员