LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
2024-08-21 13:46:43
链接:
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;
}
最新文章
- e.preventDefault() e.stopPropagation()和return false的区别
- Solr环境搭建过程中遇到的问题
- bootstrap--小李子demo
- cef3 获得js 返回值, 以及js 指挥delphi 函数的 总结参考
- Windows 8 一起学习
- BLE Hacking:使用Ubertooth one扫描嗅探低功耗蓝牙
- oracle练习题后15个
- 玩耍Hibernate系列(一)补充--基础知识
- 如何删除ArcSde Service服务
- [Django](1093, &;quot;You can&;#39;t specify target table &;#39;fee_details_invoices&;#39; for update in FROM clause&;quot;) 错误
- 深度学习(一)cross-entropy softmax overfitting regularization dropout
- python中用xpath匹配文本段落内容的技巧
- EntityFramework如何创建索引?
- Notepad++安装json插件
- Ubuntu 14.04 正式版 12.4
- mysql 锁2
- 【Linux技术】autotools制作makefile过程详解
- Before an Exam
- envi几何校正
- csv2txt.cpp
热门文章
- Python Web开发技术栈
- 为了防止页面重新自动加载,可以给a标签设置href=";javascript:void(0);";
- 函数内部声明变量的时候,一定要使用var命令。如果不用的话,你实际上声明了一个全局变量!闭包访问局部变量
- java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver 错误解决
- C# 生成随机的6位字母,包含大小写
- oracle 查询 10题
- Java 面向对象知识扩展
- js实现图片上传本地预览
- Oracle 创建与管理用户
- 字符串导出xml文件并弹出下载对话框