链接:

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.

思路:

素数表,然后暴力。

代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<string>
  5. #include<algorithm>
  6. #include<math.h>
  7. #include<vector>
  8. #include<map>
  9. using namespace std;
  10. typedef long long LL;
  11. const int INF = 1e9;
  12. const int MAXN = 1e7+10;
  13. const int MOD = 1e9+7;
  14. bool IsPrime[MAXN];
  15. int Prime[1000010];
  16. int n, tot;
  17. void Init()
  18. {
  19. memset(IsPrime, 0, sizeof(IsPrime));
  20. IsPrime[1] = 1;
  21. tot = 0;
  22. for (int i = 2;i < MAXN;i++)
  23. {
  24. if (IsPrime[i] == 0)
  25. Prime[++tot] = i;
  26. for (int j = 1;j <= tot && i*Prime[j] < MAXN;j++)
  27. {
  28. IsPrime[i*Prime[j]] = 1;
  29. if (i%Prime[j] == 0)
  30. break;
  31. }
  32. }
  33. }
  34. int main()
  35. {
  36. Init();
  37. int t, cnt = 0;
  38. scanf("%d", &t);
  39. while(t--)
  40. {
  41. printf("Case %d:", ++cnt);
  42. scanf("%d", &n);
  43. int sum = 0;
  44. for (int i = 1;i <= tot && Prime[i] <= n/2;i++)
  45. {
  46. if (IsPrime[n-Prime[i]] == 0)
  47. sum++;
  48. }
  49. printf(" %d\n", sum);
  50. }
  51. return 0;
  52. }

LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)的更多相关文章

  1. LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)

    http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...

  2. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  3. LightOJ 1259 Goldbach`s Conjecture 水题

    不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...

  4. LightOJ1259 Goldbach`s Conjecture —— 素数表

    题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture    PDF (English) Statistic ...

  5. Light oj-1259 - Goldbach`s Conjecture

                                                                                    1259 - Goldbach`s Co ...

  6. Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】

    Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...

  7. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  8. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

  9. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

随机推荐

  1. C语言单链表简单实现(简单程序复杂化)

    PS: goto还是很好玩的. #include <stdio.h> #include <stdlib.h> typedef struct _node{ int value; ...

  2. 常用Tables控件介绍(二)

    初始化:1.使用现有表单创建数据表格,定义在HTML中的字段和数据 2.使用现有的table创建数据表格,定义在HTML中的字段 3.使用JS创建数据库表格 一.初始化后,根据单元格内的值,修改显示内 ...

  3. javascript匿名函数自执行 (function(window,document,undefined){})(window,document);

    使用匿名自执行函数的作用: (function(window,document,undefined){})(window,document); 1.首先匿名函数 (function(){}) (); ...

  4. (转)项目迁移_.NET项目迁移到.NET Core操作指南

    原文地址:https://www.cnblogs.com/heyuquan/p/dotnet-migration-to-dotnetcore.html 这篇文章,汇集了大量优秀作者写的关于" ...

  5. 跨域访问MVC

    using MvcApp.Filters; using System; using System.Collections.Generic; using System.Linq; using Syste ...

  6. 图解Apache Mina

    Apache MINA 是一个用于简化开发构建高性能.高可扩展的网络应用框架.通过JAVA NIO在各种传输协议(如:TCP/IP.UDP/IP)上提供抽象的事件驱动异步API Apache MINA ...

  7. iOS-右滑返回,利用Runtime添加全屏Pop手势

    项目中经常会遇到类似需求,需要在某控制器增加全屏右滑返回功能. 在我们不隐藏 NavigationBar 的前提下,系统会自动替我增加此功能,只是它作用的范围仅仅在屏幕左边有限区域. 我们需要在整个界 ...

  8. springboot整合ActiveMQ1(基本使用)

    基本使用,https://www.tapme.top/blog/detail/2018-09-05-10-38 主备模式,https://www.tapme.top/blog/detail/2018- ...

  9. Kconfig和Makefile

    内核源码树的目录下都有Kconfig和Makefile.在内核配置make menuconfig时,从Kconfig中读出菜单,用户勾选后保存到.config中.在内核编译时,Makefile调用这个 ...

  10. Winserver-FailoverCluster验证异常

    Q:新建的2台物理机,组成一个集群,第一遍没有问题,建成后,我想重建所以就destroy掉了,但是在重建时报 错误,尝试了各种清除集群指令和重新安装failover等方法都无效. 以后不在使用Dest ...