LightOJ 1259 Goldbach`s Conjecture(数论)

XY2-100协议解析 1.XY2-100包括四路信号 : SENDCK(时钟信号)、SYNC(同步信号)、CHANNELX(X通道)、CHANNELY(Y通道) 阅读详情

Goldbach`s Conjecture

Description

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


解题思路:

4 ≤ n ≤ 10的7次方,数据稍微有点大,因此用素数筛选法时定义数组要用bool类型,因为bool只占1个字节,而int占4个字节。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

bool vis[10000005];//bool只占1个字节,int占4个字节
vector<int> v;

void get_prime(){
    memset(vis,false,sizeof(vis));
    vis[1] = true;
    for(int i = 2; i <= 10000000; i++){
        int t = 10000000/i;
        for(int j = 2; j <= t; j++)
            vis[i*j] = true;
    }
    for(int i = 2; i <= 10000000; i++)
        if(!vis[i])
            v.push_back(i);
}

int main(){
    get_prime();
    int T,t = 1;
    scanf("%d",&T);
    while(T--){
        int n,ans = 0;
        scanf("%d",&n);
        for(int i = 0; v[i] <= n/2; i++){
            int tmp = n-v[i];
            if(!vis[tmp])
                ans++;
        }
        printf("Case %d: %d\n",t++,ans);
    }
    return 0;
}


Innovus Function ECO实战:5步搞定数字后端设计中的网表修正(含Calibre LVS验证技巧) 本文提供了一份完整的Innovus Function ECO实战指南,详细解析了数字后端设计中网表修正的五步流程。从理解Function ECO概念、准备关键文件,到在Innovus中执行逻辑比对、自动布线及GUI检查,并重点攻克了ECO后Calibre LVS验证的难点与调试技巧,帮助工程师高效、精准地完成流片前的设计微调。 阅读详情

相关推荐

Android真机调试——ADB调试(含华为手机无法找到设备)

本文以Huawei Nova7为例。

lianqi2003的博客 7894

Goldbach`s Conjecture

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

rg_lzm的博客 222

基于STM32的智能衣柜系统开发实战(附完整源码与硬件设计)

本文详细介绍了基于STM32的智能衣柜系统开发实战,包括硬件设计、软件架构和云端功能实现。系统具备实时温湿度监控、自动加热除湿、紫外线杀菌等核心功能,通过STM32F103C8T6主控芯片和ESP8266无线模块实现智能控制。附完整源码与硬件设计,适合科技爱好者和开发者参考。

peach的博客 791

LightOJ 1259 Goldbach`s Conjecture

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

旺崽的博客 2643

【Unity】【Photon】Photon Fusion2 的核心Unity组件 NetworkRunner 学习笔记

本文是学习Photon Fusion2 的核心Unity组件 NetworkRunner的学习笔记。

O青草O的博客 Unity和游戏制作知识分享 1277

Java开源海外跨境电商购物商城源码,TikToK商城系统源码,外贸商城在线交易

最近很火的一款商城源码,朋友分享给我的,完整版,java开源代码,带有非常详细的搭建教程,文件都一个多G,喜欢的可以下载来研究研究!3、创建mall 数据库并导入数据,数据库名用户名为:mall 数据库密码保持为:XXKytcACPX3GbdsH。8、进入cd /data/deploy/mall-tool/目录执行./build.sh脚本。7、宝塔ssh进入cd /data/deploy/mall/ 执行./build.sh脚本。2、安装宝塔环境:安装 Redis、MySQL5.7、Ngin1.2。

百创科技 2831

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 your task is to check whether this conjecture ho

kitalekita的博客 367

Python爬虫实战:Playwright 攻克京东图书新书榜(含动态价格与分页)!

我长期专注 Python 爬虫工程化实战,主理专栏 《Python爬虫实战》:从采集策略到反爬对抗,从数据清洗到分布式调度,持续输出可复用的方法论与可落地案例。内容主打一个“能跑、能用、能扩展”,让数据价值真正做到——抓得到、洗得净、用得上。

喵手的博客 603

LightOJ1529(普通素数筛,埃拉特斯特尼筛法,欧拉筛法)

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

qq_40293424的博客 388

上下相机对位,上下贴合,上下相机映射对位场景案例

上下相机对位,上下贴合,上下相机映射对位场景案例

视觉人机器视觉的博客 1万+

【YOLOv12多模态融合改进】| TFAM:时序融合注意力模块 | 引入通道 - 空间双分支注意力机制,解决双模态特征融合中时序关联不足的问题

TFAM模块通过时序信息驱动的注意力机制,解决了双时相特征融合中时序关联不足的问题,实现了更精准的变化区域定位和特征表示。其结构轻量、泛化性强,为变化检测任务提供了一种高效的特征融合解决方案。

Limiiiing的博客 876

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平 173

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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硕士 220

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【LightOJ1259】Goldbach`s Conjecture(数论)

【LightOJ1259】Goldbach`s Conjecture(数论) 题面 Vjudge T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方案个数 题解 筛出质数后直接暴力判断就行了 质数密度没有那么大,记得节约空间 #include<iostream> #include<cstdio> #include<c...

weixin_30691871的博客 154

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Goldbach`s Conjecture LightOJ - 1259 欧拉筛(数论专题)

n=a+b 满足a,b(a<=b)都是质数,a+b=n方案个数 Input 输入一个T,代表样例数量 T(≤ 300)。 每一行输入一个n (4 ≤ n ≤ 107)。 奥奥 n是个偶数。 Output 每一行输出样例的行号以及可以表示n的两个素数之和的方式数。 Sample Input 2 6 4 Sample Output Case 1: 1 Case 2: 1 这道题爆了好多次,不是RE就是TLE,甚至还有MLE,最后在筛法中欧拉筛是最快的,这里我放一个TLE的,先对每一个数字进行标记数据范围内

qq_45891413的博客 222

LightOj 1259 Goldbach`s Conjecture -------数论

Time limit   2000 ms Memory limit   32768 kB OS   Linux Source   Problem Setter: Jane Alam Jan Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathemati...

sinat_41233888的博客 1109

Kuangbin数论专题,Goldbach`s Conjecture( LightOJ - 1259,素数欧拉线性筛)

kuangbin #include< iostream> #include< cstdio> #include< cstdlib> #include< cstring> #include< string> #include< vector> #include< algorithm> #include< que...

qq_41856950的博客 159

LightOJ1259 Goldbach`s Conjecture 线性筛

LightOJ1259 Goldbach`s Conjecture 标签 线性筛 前言 我的csdn和博客园是同步的,欢迎来访danzh-博客园~ 简明题意 给定n(n<=1e7),求两个质数的和为n的方案数 思路 筛一下质数就好了... 注意事项 prime数组不要开太了,会炸的。。。 总结 无 AC代码 #include<cstdio> c...

weixin_30416497的博客 150

lightoj 1259 Goldbach`s Conjecture

解题思路:按照常规暴力的话,结果肯定是Memory  Limit,所以这道题可以用素数筛先把素数找出来,记录在一个数组里面,等用的时候直接可以用。见代码吧!!! 这道题还有一个需要注意到,开数组的时候用bool型,因为bool型占一个字节,而int占四个字节 Goldbach's conjecture is one of the oldest unsolved problems in

W_904038290的博客 378

lightoj 1259 - Goldbach`s Conjecture【素数打表】

1259 - Goldbach`s Conjecture     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Goldbach's conjecture is one of the oldest unsolved

博客已搬迁到http://www.cnblogs.com/cniwoq/ 589

LightOJ1259 Goldbach`s Conjecture —— 素数表

题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture PDF (English) Statistics Forum Time Limit:2 second(s) Memory Limit:32 MB ...

alince20008的博客 154

Goldbach`s Conjecture LightOJ - 1259(筛法水题)

Goldbach`s Conjecture LightOJ - 1259 题意: 给你一个数n。 问: 有多少种方案可以把 n拆成两个质数。(哥德巴赫猜想) 思路: 先暴力打表。期间把质数存起来 之后存好质数后,去判断。 反思: 1e7的 int 对于 3e5的内存会MLE。。。qwq。血与泪的教训。(本题的解决方法:开bool,比int小了4倍内存) 时间上 1e7log1e7(其中log1e7约等于7,所以不会TLE) AC #include <iostream> #include

qq_45377553的博客 152

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

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

世界很大 1042

Goldbach`s Conjecture LightOJ - 1259

打表得 #include&amp;lt;bits/stdc++.h&amp;gt; using namespace std; #define fst first #define sec second #define sci(num) scanf(&quot;%d&quot;,&amp;amp;num) #define scl(num) scanf(&quot;%lld&quot;,&amp;amp

KLChen的博客 282
上一篇: Codeforces Round #340 (Div. 2) (629A,629B,629C(排列组合,动态规划),629D(线段树))
下一篇: LightOJ 1245 Harmonic Number (II)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址