Light oj-1259 - Goldbach`s Conjecture
分拆素数和,本来很水的题,但硬生生跪了18+。这题卡内存实在太凶残了,MLT了10+,TLE了10+。
题意:在1e7内验证哥德巴赫猜想,求一个数拆分成两个不同的素数和有多少中方法。
思路:打表。就是打表。
但为什么会MLE呢,因为1e7的数组实在太大了,于是换了好几种写法优化,但又面临着TLE的囧境。在山穷水尽之际百度了一遍题解,坑爹竟然就是1e7的数组打表。但我为什么MLE了呢,于是找啊找,我用的int数组,初始化用的-1,但bool型的数组直接初始化为1。are you kidding me ?多次验证之后发现只有bool型的能过,其他的果断MLE。
那就是说:bool型的数组可以达到1e7,相比int型数组要更优一点。
const int N=1e7+10;
int len=0,b[N/10];//int 数组开这么大可能会被卡。
bool a[N];
void init()
{
memset(a,1,sizeof(a));
a[0]=a[1]=0;
for(int i=2; i<N; i++)
if(a[i])
{
b[len++]=i;
if(N/i<i) continue;
for(int j=i*i; j<N; j+=i) a[j]=0;
}
}
int main()
{
init();
int t,n,t1=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int ans=0;
for(int i=0; i<len&&b[i]<=n/2; i++)
if(a[n-b[i]]) ans++;
printf("Case %d: %d\n",t1++,ans);
}
return 0;
}
哎,也算是学到了!!
Light oj-1259 - Goldbach`s Conjecture的更多相关文章
- LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...
- LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...
- LightOJ 1259 Goldbach`s Conjecture 水题
不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...
- LightOJ 1259 Goldbach`s Conjecture 素数打表
题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...
- LightOJ1259 Goldbach`s Conjecture —— 素数表
题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture PDF (English) Statistic ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
- Goldbach's Conjecture
Goldbach's Conjecture Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
随机推荐
- 506 Relative Ranks 相对名次
给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌.前三名运动员将会被分别授予 “金牌”,“银牌” 和“ 铜牌”("Gold Medal", "Silve ...
- ImageView加载长图(适用不需要缩放的情况)
此案例适用于加载网络长图且图片的宽和高已知的情况.由于ImageView加载图片有一个4096*4096的限制,所以对于巨长图的加载比较麻烦,需要我们自己去手动处理. 有两种解决方案:第一种就是比较l ...
- Problem 2238 Daxia & Wzc's problem 1627 瞬间移动
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...
- RabbitMQ九:远程过程调用RPC
定义 RPC(Remote Procedure Call Protocol)——远程过程调用协议:它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.RPC协议假定某些传输协议 ...
- 外文翻译 《How we decide》多巴胺的预言 第一节
这是第二章的起始... 书的导言 1991年2月24日凌晨.第一与第二海军陆战队大批向北进入了沙特阿拉伯的沙漠地带,他们从这来进入科威特.这批军队是伊拉克入侵8个月以来,同盟国第一批进入科威特的部队. ...
- AJPFX总结方法重载与方法重写的区别
方法重载在同一个类中,可以出现同名方法,但是这些同名方法的参数列表必须不同,这样定义方法叫做方法重载.方法重载的特点重载的注意事项重载与返回值无关重载与具体的变量标识符无关重载只与方法名与参数相关重载 ...
- jdk1.8新日期时间类(DateTime、LocalDateTime)demo代码
//获取当前时间 LocalDateTime d0 = LocalDateTime.now(); System.out.println(DataConvertUtil.localDateTimeToS ...
- BottomNavigationBar底部导航条用法
先来张效果图 接下来是实现过程 1.加入依赖 compile 'com.ashokvarma.android:bottom-navigation-bar:1.3.0' 2.xml布局 fragment ...
- 46 Simple Python Exercises-Higher order functions and list comprehensions
26. Using the higher order function reduce(), write a function max_in_list() that takes a list of nu ...
- docker 新手入门 (阿里镜像仓库的使用)
创建镜像仓库后的步骤是: https://help.aliyun.com/document_detail/60743.html?spm=a2c4g.11186623.6.546.79be52f3y ...