F - Goldbach`s Conjecture kuangbin 基础数论
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
Hint
- An integer is said to be prime, if it is divisible by exactly two different integers. First few primes are 2, 3, 5, 7, 11, 13, ...
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<cstring>
- #include<sstream>
- #include<algorithm>
- #include<queue>
- #include<deque>
- #include<iomanip>
- #include<vector>
- #include<cmath>
- #include<map>
- #include<stack>
- #include<set>
- #include<fstream>
- #include<memory>
- #include<list>
- #include<string>
- using namespace std;
- typedef long long LL;
- typedef unsigned long long ULL;
- #define MAXN 10000001
- #define L 31
- #define INF 1000000009
- #define eps 0.00000001
- /*
- 打表 把所有素数存到一个vector中
- 然后用一个map保存所有和出现的次数
- 然后直接找就可以
- */
- bool notprime[MAXN];
- vector<int> prime;
- void Init()
- {
- memset(notprime, false, sizeof(notprime));
- notprime[] = true;
- for (int i = ; i < MAXN; i++)
- {
- if (!notprime[i])
- {
- prime.push_back(i);
- for (int j = i + i; j < MAXN; j += i)
- notprime[j] = true;
- }
- }
- }
- int main()
- {
- Init();
- int T,n;
- cin >> T;
- for(int cas=;cas<=T;cas++)
- {
- cin >> n;
- vector<int>::iterator p = lower_bound(prime.begin(), prime.end(), n/);
- //cout << *p << endl;
- int cnt = ;
- for (vector<int>::iterator it = prime.begin(); it <= p && *it<=n/; it++)
- {
- if (!notprime[n - *it])
- {
- //cout << *it << ' ' << n - *it << endl;
- cnt++;
- }
- }
- printf("Case %d: %d\n", cas, cnt);
- }
- return ;
- }
- #include<iostream>
F - Goldbach`s Conjecture kuangbin 基础数论的更多相关文章
- F - Goldbach`s Conjecture 对一个大于2的偶数n,找有多少种方法使两个素数的和为n;保证素数a<=b; a+b==n; a,b都为素数。
/** 题目:F - Goldbach`s Conjecture 链接:https://vjudge.net/contest/154246#problem/F 题意:对一个大于2的偶数n,找有多少种方 ...
- 【LightOJ1259】Goldbach`s Conjecture(数论)
[LightOJ1259]Goldbach`s Conjecture(数论) 题面 Vjudge T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方 ...
- [暑假集训--数论]poj2262 Goldbach's Conjecture
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
- Goldbach’s Conjecture(信息学奥赛一本通 1622)
[题目描述] 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于 44 的偶数都可以拆成两个奇素数之和. 比如: 8=3+5 20=3+17=7+13 42=5+37=1 ...
- 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 ...
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
随机推荐
- codevs3342绿色通道(单调队列优化dp)
3342 绿色通道 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description <思远高考绿色通道>(Green Pass ...
- AirtestIDE详解(跨平台的UI自动化编辑器)
Airtest 是网易出品的一款基于图像识别和poco控件识别的一款UI自动化测试工具. AirtestIDE 是一个跨平台.多端(Windows.web.android.ios.游戏)的UI自动化测 ...
- Django基于JWT实现微信小程序的登录和鉴权
什么是JWT? JWT,全称Json Web Token,用于作为JSON对象在各方之间安全地传输信息.该信息可以被验证和信任,因为它是数字签名的. 与Session的区别 一.Session是在服务 ...
- Java中的自定义注解
## 元注解 要声明一个注解, 我们需要元注解, 元注解是指注解的注解,包括@Retention, @Target, @Document, @Inherited. @Retention 注解的保留位置 ...
- 321 Create Maximum Number 拼接最大数
已知长度分别为 m 和 n 的两个数组,其元素由 0-9 构成,直观地表示两个自然数各位上的数字.现在从这两个数组中选出 k (k <= m + n) 个数字拼接成一个新的数,要求从同一个数组中 ...
- [转]Oracle Client 11g安裝經驗
本文转自:http://www.dotblogs.com.tw/shadow/archive/2011/11/08/54759.aspx 開發環境:本機(Win XP)的ASP.net 4 WebSi ...
- iOS动画——DynamicAnimate
力学动画 以dynamicAnimate为首的力学动画是苹果在iOS7加入的API,里面包含了很多力学行为,这套API是基于Box2d实现的.其中包含了重力.碰撞.推.甩.和自定义行为. 涉及到的类如 ...
- UVM基础之----uvm_object
uvm_void The uvm_void class is the base class for all UVM classes. uvm_object: The uvm_object class ...
- (三)Python 学习第三天--GUI桌面项目
(代码参考了别人的代码,只做学习用途!!!最近因为写论文,好久没有记录,好内疚...今天学习了一个小案例,做一下) 主要使用模块:tkinter 代码如下: from tkinter import * ...
- Nagios事件机制实践
Nagios事件机制实践 blog地址:http://www.cnblogs.com/caoguo 一.事件触发执行脚本 [root@Nagios ~]# cd /usr/local/nagios/ ...