LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
链接:
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;
}
LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)的更多相关文章
- LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...
- LightOJ 1259 Goldbach`s Conjecture 素数打表
题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...
- LightOJ 1259 Goldbach`s Conjecture 水题
不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...
- LightOJ1259 Goldbach`s Conjecture —— 素数表
题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture PDF (English) Statistic ...
- Light oj-1259 - Goldbach`s Conjecture
1259 - Goldbach`s Co ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
- 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 ...
随机推荐
- 【C++札记】赋值兼容
赋值兼容的规则时在需要使用基类对象的任何地方都可以使用公有派生类对象来替代.公有继承派生类可获得基类中除构造函数,析构函数外的所有成员,能用基类解决的问题,派生类也能解决.更直白点说,如果一个类是从一 ...
- 数据分析-numpy的用法
一.jupyter notebook 两种安装和启动的方式: 第一种方式: 命令行安装:pip install jupyter 启动:cmd 中输入 jupyter notebook 缺点:必须手动去 ...
- 一行代码让3D翻转后的文本恢复清晰
FlashPlayer10提供的3D功能有一个相当蛋疼的问题:只要设置过rotationX.rotationY或者rotationZ属性,显示对象里面的文字(尤其是设备字体,位图文本)就会一直处于模糊 ...
- QT支持TTF字体
1.编译QT库时需要支持TTF字体 ./configure -qt-freetype -fontconfig ... 2.将TTF字符库拷贝到QT_QPA_FONTDIR下 # 注意,如果不清楚字体所 ...
- c# webapi 过滤器token、sign认证、访问日志
1.token认证 服务端登录成功后分配token字符串.记录缓存服务器,可设置有效期 var token = Guid.NewGuid().ToString().Replace("-&qu ...
- Python之TensorFlow的基本介绍-1
一.TensorFlow™是一个基于数据流编程(dataflow programming)的符号数学系统,被广泛应用于各类机器学习(machine learning)算法的编程实现,其前身是谷歌的神经 ...
- 5_PHP数组_3_数组处理函数及其应用_2_数组统计函数
以下为学习孔祥盛主编的<PHP编程基础与实例教程>(第二版)所做的笔记. 一.数组统计函数 数组统计函数是指统计数组各元素的值,并对这些值进行简单分析. 1. count() 函数 该函数 ...
- src属性与浏览器渲染
img标签 只要设置了src属性, 就会开始下载,因此可以使用这个特性,配合display:none,默默的下载一些图片,用的时候直接用,快了那么一丢丢~ 注意:不一定要添加到文档后才会开始下载,是只 ...
- C++线程同步与互斥总结
互斥:当多个线程访问同一个全局变量,或者同一个资源(比如打印机)的时候,需要进行线程间的互斥操作来保证访问的安全性. 临界区.互斥体.事件和信号量都可以实现线程互斥.但如果仅仅需要实现互斥功能,推荐前 ...
- springboot启动后执行一段代码的方式
文章转载自: https://www.cnblogs.com/zuidongfeng/p/9926471.html https://blog.csdn.net/zknxx/article/detail ...