LightOJ 1259 Goldbach`s Conjecture
来源:互联网 发布:如何申请淘宝网店步骤 编辑:程序博客网 时间:2024/06/10 02:06
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/F
Description
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.
Input
Input starts with an integer T (≤ 300), denoting the number of test cases.
Each case starts with a line containing an integer n (4 ≤ n ≤ 107, n is even).
Output
For each case, print the case number and the number of ways you can express n as sum of two primes. To be more specific, we want to find the number of (a, b) where
1) Both a and b are prime
2) a + b = n
3) a ≤ b
Sample Input
2
6
4
Sample Output
Case 1: 1
Case 2: 1
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#include <limits>#include <queue>#include <stack>#include <vector>#include <map>using namespace std;#define N 10005000#define INF 0x3f3f3f3f#define PI acos (-1.0)#define EPS 1e-8#define met(a, b) memset (a, b, sizeof (a))bool isprime[N] = {1, 1, 0};int a[N/10], k;void prime (){ k = 0; for (int i=2; i<N; i++) { if (!isprime[i]) { a[k++] = i; for (int j=i+i; j<N; j+=i) isprime[j] = 1; } }}int main (){ int t, n, flag = 1; scanf ("%d", &t); prime (); while (t--) { int ans = 0; scanf ("%d", &n); for (int i=0; i<k; i++) { if (a[i] > n-a[i]) break; if (!isprime[n-a[i]]) ans++; } printf ("Case %d: %d\n", flag++, ans); } return 0;}
- lightOJ 1259 Goldbach`s Conjecture
- LightOJ - 1259 Goldbach`s Conjecture
- LightOJ 1259 Goldbach`s Conjecture
- LightOJ 1259 Goldbach`s Conjecture
- LightOJ - 1259 Goldbach`s Conjecture
- LightOJ 1259 Goldbach`s Conjecture
- LightOJ 1259 Goldbach`s Conjecture
- Goldbach`s Conjecture LightOJ 1259
- Goldbach`s Conjecture LightOJ 1259
- lightoj 1259 Goldbach`s Conjecture
- LightOJ 1259 Goldbach`s Conjecture
- Goldbach`s Conjecture LightOJ
- Goldbach`s Conjecture LightOJ
- 【哥德巴赫猜想】LightOJ Goldbach`s Conjecture 1259
- LightOJ 1259 Goldbach`s Conjecture(数论)
- lightoj 1259 - Goldbach`s Conjecture 【素数筛】
- LightOj 1259-Goldbach`s Conjecture(素数打表)
- LightOJ 1259 Goldbach`s Conjecture(证明哥德巴赫猜想)
- HTML <input type='file'> File Selection Event
- 多线程之间的同步控制
- 第四周项目3-单链表的应用
- 单链表建立
- 写点什么吧,作为机器学习分类的开篇……
- LightOJ 1259 Goldbach`s Conjecture
- 用两个队列实现一个栈 JAVA实现
- 第4周实践项目3 - 单链表应用(1)
- 文章标题
- Fresco 源码分析(四) 后台数据返回到前台的处理 - Drawable体系的介绍(3) 遗留任务预览
- 第四周项目1建立单链表
- 第四周 建立单链表
- UVa 1585 Score【数组处理】
- 文章标题