Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)
题意:
就是哥德巴赫猜想。。。任意一个偶数 都可以分解成两个(就是一对啦)质数的加和
输入一个偶数求有几对。。
解析:
首先! 素数打表。。因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质数 。。。 我真是蠢啊
还有 vis要用bool类型的!!!! int会直接爆
代码如下:
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define maxn 10000000
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f;
LL primes[];
bool vis[maxn];
int cnt = ;
void init()
{
mem(vis,);
primes[] = ; primes[] = ;
for(int i=; i<maxn; i++)
if(!vis[i])
{
primes[cnt++] = i;
for(LL j=(LL)i*i; j<maxn; j+=i)
vis[j] = ;
}
} int main()
{
int T;
init();
int res = ;
cin>> T;
while(T--)
{
int ans = ;
int n;
cin>> n;
for(int i=; i<cnt && primes[i] <= n/; i++)
{
if(!vis[n-primes[i]])
ans++;
}
printf("Case %d: %d\n",++res,ans); } return ;
}
Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)的更多相关文章
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
- Lightoj 1370 素数打表 +二分
1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Time Limit: 2 second(s) Memory Limit: 32 MB ...
- Light oj-1259 - Goldbach`s Conjecture
1259 - Goldbach`s Co ...
- 哥德巴赫猜想-nefu2 & 分拆素数和 hdu2098
哥德巴赫猜想-nefu2 & 分拆素数和 hdu2098 //哥德巴赫猜想 #include <iostream> #include <cmath> #include ...
- LightOJ 1259 Goldbach`s Conjecture 素数打表
题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...
- LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
- HDU 1397 Goldbach's Conjecture【素数打表】
题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...
- LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...
随机推荐
- BZOJ1185 HNOI2007 最小矩形覆盖 凸包、旋转卡壳
传送门 首先,肯定只有凸包上的点会限制这个矩形,所以建立凸包. 然后可以知道,矩形上一定有一条边与凸包上的边重合,否则可以转一下使得它重合,答案会更小. 于是沿着凸包枚举这一条边,通过旋转卡壳找到离这 ...
- DataWorks使用小结(二)——功能面板使用指南
一.数据开发 1.任务开发 新建表 野路子可以直接新建一个任务,粘贴DDL,手动运行任务即可完成建表 正常应当是在“数据管理”->数据表管理中建表: 支持可视化建表和DDL建表(配合之前的宏,建 ...
- AtCoder ExaWizards 2019 简要题解
AtCoder ExaWizards 2019 简要题解 Tags:题解 link:https://atcoder.jp/contests/exawizards2019 很水的一场ARC啊,随随便便就 ...
- Deep Learning(深度学习)学习笔记整理系列之(一)(转)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-0 ...
- ubuntu12.04安装squid
一:简介 1.Squid:优化Web交付 Squid是支持HTTP,HTTPS,FTP等的Web的缓存代理.它通过缓存和重用经常请求的网页来减少带宽并缩短响应时间.Squid拥有广泛的访问控制,是一个 ...
- React.js 开发参见问题 Q&A
文章中我整理了 React.js 开发过程中一些参见问题的解答汇总,供大家参考. 1. 一些课程资源 课程完整的思维导图请查考文章:React.js 入门与实战课程思维导图,我使用的思维导图软件是 M ...
- [T-ARA][남주긴 아까워][给别人可惜了]
歌词来源:http://music.163.com/#/song?id=29343992 作曲 : 二段横踢/Radio Galaxi [作曲 : 二段横踢/Radio Galaxi] 作词 : 二段 ...
- Linux下防御DDOS攻击的操作梳理
DDOS的全称是Distributed Denial of Service,即"分布式拒绝服务攻击",是指击者利用大量“肉鸡”对攻击目标发动大量的正常或非正常请求.耗尽目标主机资源 ...
- Gitblit版本服务器环境部署记录
Gitblit介绍Gitblit 是一个纯 Java 库用来管理.查看和处理 Git 资料库.相当于 Git 的 Java 管理工具,支持linux系统.Git是分布式版本控制系统,它强调速度.数据一 ...
- LINUX实践之模块
模块实践 --关于模块代码部分 ---首先是.c代码: 一定会用到的函数有这几个:module_init().module_exit().MODULE_LICENSE() 会用到的头文件:module ...