Goldbach`s Conjecture LightOJ - 1259(筛素数)

POJ2262-Goldbach's Conjecture 北大POJ2262-Goldbach's Conjecture 解题报告+AC代码 立即下载

Goldbach`s Conjecture

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.


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

Note

1.      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, ...

这道题本身没有什么难度,但是这道题有几个点卡你
1.筛素数后要把素数存下来遍历素数,如果直接遍历会超时
2.筛素数时判断素数的数组要开1e7+1毫无疑问,因为要筛选这么多素数,但是存素数的数组如果也开这么大就内存超限了。。
所以要开小一点1e6就过了
好坑
code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1e7+1;
const int N = 1e6;
bool isprime[maxn];
int cnt;
int prime[N];
void init(){
    memset(isprime,true,sizeof(isprime));
    cnt = 0;
    isprime[0] = isprime[1] = false;
    for(int i = 2; i < maxn; i++){
        if(isprime[i]){
            prime[cnt++] = i;
            for(int j = i + i; j < maxn; j += i){
                isprime[j] = false;
            }
        }
    }
}
int main(){
    init();
    int t,cas = 0;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        int ans = 0;
        for(int i = 0; i < cnt && prime[i] <= n/2; i++){
            if(isprime[n-prime[i]]) ans++;
        }
        printf("Case %d: %d\n",++cas,ans);
    }
    return 0;
}


树莓派安装snowboy 1、树莓派换源 参考链接:https://blog.csdn.net/qq_43556844/article/details/113615915 2、更新pip3 参考链接:https://blog.csdn.net/qq_43556844/article/details/113616214 3、存取麦克风 我们使用PortAudio作为音频输入/输出的跨平台支持。我们还使用sox作为快速实用程序来检查麦克风设置是否正确。 sudo apt-get install python-pyaudio python 阅读详情

相关推荐

Pyside6实战:3种.ui文件加载方式对比(附完整代码示例)

本文深入解析Pyside6中3种.ui文件加载方式的优劣与性能优化策略,包括动态加载QUiLoader、预编译方案及混合策略。通过实测数据和完整代码示例,帮助开发者根据项目需求选择最优解,提升界面加载效率与内存管理。

weixin_30897233的博客 88

LightOJ - 1259

Goldbach`s Conjecture 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 t...

creator平 172

【计算机图形学】Pov-Ray画的垃圾小车

效果: 代码: #include "colors.inc" #include "metals.inc" #include "glass.inc" //相机 //这个位置车子刚好落在草地上了 camera { location direction z*1.5 right x*image_width/image_height look_at

lishichengyan的博客 1749

Goldbach‘s Conjecture LightOJ - 1259 (验证哥德巴赫猜想+素数筛+暴力+素数个数的公式)

传送门 题意:T(<=300)组样例,每组样例给一个数偶数n(4<=n<=1e7),求出满足a+b=n;a<=b;a,b均为素数这三个条件的(a,b)组数。 题解:不要想那么难(首先想暴力做法,能暴力就暴力),素数筛之后5e6内素数不超过4e5,样例组数不超300,所以时间复杂度不超过O(300*4e5=1.2e8),时限为两秒,比较稳。 补充:x的素数个数估计。参考资料素数个数求解与素数的判定 代码: #include <bits/stdc++.h&.

I_have_a_world的博客 218

iPhone用户必看:不装App也能搞定GitHub 2FA验证的3种方法(附恢复码管理技巧)

本文为iPhone用户提供了无需安装第三方App即可完成GitHub双重身份验证(2FA)的三种原生方案:利用相机扫码与iCloud钥匙串自动填充、使用iCloud钥匙串内置的TOTP验证码生成器,以及借助Safari浏览器扩展。文章详细解析了每种方法的操作步骤、适用场景,并重点强调了恢复码的安全管理与多层备份策略,帮助开发者在提升账户安全的同时,享受苹果生态的无缝便捷体验。

weixin_29324401的博客 651

【电子元件篇】MOSFET场效应管作用、选型和测量指南-超简单解读

场效应管是一种电压控制型半导体器件,相比三极管具有输入阻抗高、噪声小、功耗低等优势。主要分为结型和绝缘栅型两大类,后者又可分为耗尽型和增强型MOS管。场效应管通过栅极电压控制漏极电流,具有转移特性和输出特性两大静态特性,以及快速的开关特性。其关键参数包括饱和漏源电流、夹断电压、跨导等,应用场景涵盖信号放大、恒流源、阻抗变换等领域。使用时需根据电路需求选择合适类型,如结型管适合一般放大,功率MOSFET适合高压大电流场合。检测时可用万用表电阻档初步判断好坏和放大能力。

2301_81299416的博客 2540

Goldbach`s Conjecture

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].

wanghandou的博客 483

RU.EXE实用指南:从基础操作到高级调试技巧

本文是RU.EXE(RW Everything)的实用指南,详细介绍了这款硬件调试工具从基础操作到高级技巧的全过程。文章阐述了RU.EXE作为直接读写硬件寄存器、内存和PCI配置空间的强大工具,如何帮助硬件工程师和开发人员高效进行底层系统调试与故障排查,并强调了安全操作的重要性。

weixin_29228203的博客 278

lightoj 1259 - Goldbach`s Conjecture 【素数筛】

题目链接:lightoj 1259 - Goldbach`s Conjecture

世界很大 1042

YOLO26 旋转框检测 OBB 技术:角度预测与解码优化

YOLO26旋转框检测技术通过CSL角度编码有效解决了OBB检测中的周期性问题。该技术采用5参数表示法(cx,cy,w,h,θ),在检测头中分别处理分类、回归和角度预测。核心创新点包括:1)使用高斯或三角窗口的CSL编码对角度进行平滑表示;2)通过加权平均解码角度,避免边界不连续问题。该方法在遥感、文本检测等需要精确方向信息的场景中表现优异,相比传统HBB框可提升定位精度30%以上,同时保持了YOLO系列的高效特性。

一键难忘的博客 520

【大模型】DeepSeek 高级提示词技巧使用详解

DeepSeek 高级提示词技巧使用详解

congge 1万+

Goldbach`s Conjecture (素数打表)

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]. ...

自渡的博客 2166

微信小程序 - 最新详细实现“全局实时监听页面发生跳转“ 当页面跳转后立即捕捉并触发某个操作或调用处理函数,小程序整个项目无时无刻只要路由发生变化改变了就能监听,时刻检测页面URL变化(获取路由数据)

微信小程序,vue2,vue3,监听路由,如何监听路由发生变化,如何watch监听路由,怎么全局监听页面发生变化,实现当页面路由发生变化时执行一个函数,当路由变化时执行一些操作执行一段代码,怎么监听路由变化时触发一个函数,监听页面变化,页面间的跳转如何监听,页面跳转时怎么拿到路由及参数,页面路由变化时拿到参数和url,使用watch监听路由变化,页面跳转后怎么触发事件,怎么监听页面跳转,监听页面跳转并拿到路由url路径,小程序怎么全局定义一个专门监听路由的函数,小程序怎么无时无刻实时监听路由页面跳转,监听当

🏆 前端领域优质创作者 4474

LightOJ - 1259 Goldbach`s Conjecture 素数筛

题目: 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 ...

zamaochick的博客 205

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Goldbach`s Conjecture LightOJ - 1259(素数筛)

Goldbach`s Conjecture LightOJ - 1259(素数筛) 题目链接 题意: 著名的哥德巴赫猜想问题 每个大于2的偶数,都能分解为两个素数a,b的和 然后题目要求:a<=b; 给定n,求有多少对a,b符合条件,并输出 4 ≤ n ≤ 10^7,n是偶数 题解: 直接运用素数筛:埃氏筛和欧拉筛都可以 提前打下表 #include<cstdio> #inclu...

serendipity的博客 250

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LightOJ 1259 Goldbach`s Conjecture (素数筛)

题意:给出n,求有几组能将n表示为两素数和的方法。 题解:素数筛 wa了无数次给我整蒙了,数组大小太难把控了,vector无敌好吧。 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<queue> #include<st

gongyuandaye的博客 203

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

F - Goldbach`s Conjecture LightOJ - 1259(素数筛)

F - Goldbach`s Conjecture LightOJ - 1259 题目链接:https://vjudge.net/contest/70017#problem/F 题目: Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathema...

weixin_30633949的博客 182

LightOJ 1259 - Goldbach`s Conjecture(基础数论筛素数)

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]. N...

在读NLP硕士 219

LightOJ - 1259 Goldbach`s Conjecture (素数筛)

#include<cstdio> using namespace std; /* 给一个偶数n,求有多少对素数为n[4,e^7] a<=b n=a+b a和b为素数 */ const int maxn=1e6+5; const int maxm=1e7+5; int p; int prime[maxn]; bool is_prime[maxm]; //素数筛 void sieve(int n) {

zhuxi的博客 379

素数筛 LightOJ - 1259 Goldbach`s Conjecture

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

zero 250

Goldbach`s Conjecture LightOJ - 1259 素数筛 暴力水题

直接埃氏筛法莽 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; const int maxn=1e7+100; c...

weixin_41544329的博客 235

LightOJ 1259 Goldbach`s Conjecture(素数筛)

Goldbach`s Conjecture 题解:素数打表+暴力枚举。 #include&amp;amp;lt;bits/stdc++.h&amp;amp;gt; using namespace std; const int N = 1e7+10, tot = N/log(N)+ 100000; int prime[tot]; bool vis[N]; int init() { int k = 0; for(int i ...

Eternally831143的博客 262

LightOJ - 1259 E - Goldbach`s Conjecture(筛素数)(内存问题)

题干: 就是验证哥德巴赫猜想。 输入的是一个偶数n,求n能拆成多少种两个素数的和。 4 ≤ n ≤ 10710^7107, n is even 思路: 我们先根据数据范围筛出所有素数,然后拿这些素数去减n,判断它是否为素数,如果为素数ans++。 注意数据范围是10710^7107,开int数组的会出错,所以判断素数用bool数组 #include &lt;cstdio&gt; #include ...

苍界的博客 200

Goldbach`s Conjecture LightOJ - 1259(素数筛模板题)

题意:n=a+b,满足a,b(a<=b)都是质数,求a+b=n方案个数。 题解:模板题,有个坑点:bool数组1e7不会MLE,但是int会 AC代码: #include <iostream> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <queue> #include <algorithm>

Alanrookie的博客 272
上一篇: Leading and Trailing LightOJ - 1282(数论)
下一篇: Ithea Plays With Chtholly (模拟)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值