2018.04.22ACM--训练题(计蒜客)B

Description:


Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and all of mathematics. It states:


Every even integer greater than 2 can be expressed as the sum of two primes.


The actual verification of the Goldbach conjecture shows that even numbers below at least 1e14 can be expressed as a sum of two prime numbers. 


Many times, there are more than one way to represent even numbers as two prime numbers. 


For example, 18=5+13=7+11, 64=3+61=5+59=11+53=17+47=23+41, etc.


Now this problem is asking you to divide a postive even integer n (2<n<2^63) into two prime numbers.


Although a certain scope of the problem has not been strictly proved the correctness of Goldbach's conjecture, we still hope that you can solve it. 


If you find that an even number of Goldbach conjectures are not true, then this question will be wrong, but we would like to congratulate you on solving this math problem that has plagued humanity for hundreds of years.


Input:


The first line of input is a T means the number of the cases.


Next T lines, each line is a postive even integer n (2<n<2^63).


Output:


The output is also T lines, each line is two number we asked for.


T is about 100.


本题答案不唯一,符合要求的答案均正确
样例输入


1
8
样例输出


3 5



翻译:

描述:




哥德巴赫猜想是数论和数学中最古老,最着名的未解决问题之一。它指出:

每个大于2的偶数都可以表示为两个素数的总和。

哥德巴赫猜想的实际验证表明,至少1e14以下的偶数可以表示为两个素数的和。

很多时候,将偶数表示为两个素数的方法不止一种。

例如,18 = 5 + 13 = 7 + 11,64 = 3 + 61 = 5 + 59 = 11 + 53 = 17 + 47 = 23 + 41等

现在这个问题要求你将正整数n(2 <n <2 ^ 63)分成两个素数。

虽然一定范围的问题没有被严格证明哥德巴赫猜想的正确性,但我们仍然希望你能解决它。

如果你发现偶数的哥德巴赫猜想不是真的,那么这个问题就会出错,但是我们要祝贺你解决这个数百年来困扰人类的数学问题。

输入:

第一行输入是T意味着案件的数量。

接下来的T行,每行是一个正整数n(2 <n <2 ^ 63)。

输出:

输出也是T线,每行都是我们要求的两个数字。

T是大约100。


预处理前1e6范围内的素数(素数定理保证2^63内无解概率几乎为0)

对于每次询问n,逐个暴力这些素数ai,利用素数判定判断n-ai是否是素数。

提交的很多的超时和错误原因是因为未考虑到大数据(大于2^62、小于2^63)时的溢出。

由于数据范围是long long,素数判定时存在左移位,故在素数判定可采用unsigned long long防止溢出。


import java.util.*;
import java.math.*;
public class Main {
	public static void main(String args[]) {
		int[] oddPrime = new int[1500];
		int numPrime = 0;
		for(int i=2;i<=10000;i++) {
			int flag=0;
			for(int j=2;j*j<=i;j++) {
				if(i%j==0) {
					flag=1;
					break;
				}
			}
			if(flag==0) {
				oddPrime[numPrime]=i;
				numPrime ++;
			}
		}
		Scanner cin = new Scanner(System.in);
		int T = cin.nextInt();
		while(T>0) {
			BigInteger x = cin.nextBigInteger();
			for(int i=0;i<numPrime;i++) {
				BigInteger delta = x.subtract(BigInteger.valueOf(oddPrime[i]));
				if(delta.isProbablePrime(100)) {
					System.out.println(oddPrime[i]+" "+delta.toString());
					break;
				}
			}
			T--;
		}
		cin.close();
	}
}

内容概要:该库专为研究生入学考试计算机组成原理科目设计,涵盖名校考研真、经典教材课后习、章节库和模拟试四大核心模块。名校考研真精选多所知名高校的计算机组成原理科目及计算机联考真,并提供详尽解析,帮助考生把握考研命趋势与难度。经典教材课后习包括白中英《计算机组成原理》(第5版)和唐朔飞《计算机组成原理》(第2版)的全部课后习解答,这两部教材被众多名校列为考研指定参考书目。章节库精选代表性考,注重基础知识与重难点内容,帮助考生全面掌握考试大纲要求的知识点。模拟试依据历年考研真规律和热门考点,精心编制两套全真模拟试,并附标准答案,帮助考生检验学习成果,评估应试能力。 适用人群:计划参加研究生入学考试并报考计算机组成原理科目的考生,尤其是需要系统复习和强化训练的学生。 使用场景及目标:①通过研读名校考研真,考生可以准确把握考研命趋势与难度,有效评估复习成效;②通过经典教材课后习的练习,考生可以巩固基础知识,掌握解技巧;③通过章节库的系统练习,考生可以全面掌握考试大纲要求的各个知识点,为备考打下坚实基础;④通过模拟试的测试,考生可以检验学习成果,评估应试能力,为正式考试做好充分准备。 其他说明:该库不仅提供详细的目解析,还涵盖了计算机组成原理的各个方面,包括计算机系统概述、数据表示与运算、存储器分层、指令系统、中央处理器、总线系统和输入输出系统等。考生在使用过程中应结合理论学习与实践操作,注重理解与应用,以提高应试能力和专业知识水平。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值