卡空间!

我的天,今天让一道卡空间了,关键是他不提示ME, 给我一个RE 我所以我一直在找数组越界的错。 真的是醉了(02 不要嘲笑我哈哈)。

下边来写一下数据的空间大小吧,一个int是4字节,1kb 就是250个int,1 MB 就是2.5* 105int,long long 和 bool 分别是 8 字节和1字节,char 是 1 字节,换算起来很简单。
更新一下:直接记住4 mb 是 1e 6 int 的大小就可以了,这样记比较方便ne .

写上题目吧: 感谢你让我成长了一些

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

Both a and b are prime
a + b = n
a ≤ b

Sample Input

2
6
4

Sample Output

Case 1: 1
Case 2: 1

代码真的很短~

#include <iostream>
#include <cstring>

using namespace std;

const int N = 1e7 + 10;

int prime[666666], idx; // 这里 要开成 66....  因为1e7之间的质数就 65... 多个

bool vis[N];


void get()
{
    
    vis[1] = true; vis[0] = true;
	for (int i = 2; i <= 1e7; i++)
	{
		if (!vis[i]) prime[idx++] = i;
		for (int j = 0; prime[j] <= 1e7 / i; j++)
		{
			vis[i * prime[j]] = true;
			if (i % prime[j] == 0) break;
		}
	}
}
int main()
{
	get();
	int T; cin >> T;
	
	int cases = 1;
	while (T--)
	{
		int n; cin >> n;
		int res = 0;
		for (int i = 0; i < idx; i++)
		{
			if (prime[i] > n / 2) break;
			if (n - prime[i] >= 2 && !vis[n - prime[i]]) res++;
		}
        printf("Case %d: %d\n", cases ++, res);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值