链接:

https://vjudge.net/problem/LightOJ-1259

题意:

Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:

Every even integer, greater than 2, can be expressed as the sum of two primes [1].

Now your task is to check whether this conjecture holds for integers up to 107.

思路:

素数表,然后暴力。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map> using namespace std;
typedef long long LL;
const int INF = 1e9; const int MAXN = 1e7+10;
const int MOD = 1e9+7; bool IsPrime[MAXN];
int Prime[1000010];
int n, tot; void Init()
{
memset(IsPrime, 0, sizeof(IsPrime));
IsPrime[1] = 1;
tot = 0;
for (int i = 2;i < MAXN;i++)
{
if (IsPrime[i] == 0)
Prime[++tot] = i;
for (int j = 1;j <= tot && i*Prime[j] < MAXN;j++)
{
IsPrime[i*Prime[j]] = 1;
if (i%Prime[j] == 0)
break;
}
}
} int main()
{
Init();
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%d", &n);
int sum = 0;
for (int i = 1;i <= tot && Prime[i] <= n/2;i++)
{
if (IsPrime[n-Prime[i]] == 0)
sum++;
}
printf(" %d\n", sum);
} return 0;
}

最新文章

  1. e.preventDefault() e.stopPropagation()和return false的区别
  2. Solr环境搭建过程中遇到的问题
  3. bootstrap--小李子demo
  4. cef3 获得js 返回值, 以及js 指挥delphi 函数的 总结参考
  5. Windows 8 一起学习
  6. BLE Hacking:使用Ubertooth one扫描嗅探低功耗蓝牙
  7. oracle练习题后15个
  8. 玩耍Hibernate系列(一)补充--基础知识
  9. 如何删除ArcSde Service服务
  10. [Django](1093, &amp;quot;You can&amp;#39;t specify target table &amp;#39;fee_details_invoices&amp;#39; for update in FROM clause&amp;quot;) 错误
  11. 深度学习(一)cross-entropy softmax overfitting regularization dropout
  12. python中用xpath匹配文本段落内容的技巧
  13. EntityFramework如何创建索引?
  14. Notepad++安装json插件
  15. Ubuntu 14.04 正式版 12.4
  16. mysql 锁2
  17. 【Linux技术】autotools制作makefile过程详解
  18. Before an Exam
  19. envi几何校正
  20. csv2txt.cpp

热门文章

  1. Python Web开发技术栈
  2. 为了防止页面重新自动加载,可以给a标签设置href=&quot;javascript:void(0);&quot;
  3. 函数内部声明变量的时候,一定要使用var命令。如果不用的话,你实际上声明了一个全局变量!闭包访问局部变量
  4. java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver 错误解决
  5. C# 生成随机的6位字母,包含大小写
  6. oracle 查询 10题
  7. Java 面向对象知识扩展
  8. js实现图片上传本地预览
  9. Oracle 创建与管理用户
  10. 字符串导出xml文件并弹出下载对话框