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

题目大意就是给你一个偶数,让你把偶数分成两个素数和,输出任意一组答案即可
打表发现可能的分解情况中,较小的那个素数非常小,最大不过在一万左右
所以现在问题就变成了如何快速的判断一个数是否为素数
所以要用“Miller-Rabin素数检测算法”,具体参加如下博客
https://blog.csdn.net/zengaming/article/details/51867240
要注意的是题目给的数非常大,即使用long long存稍微算一下加法也会炸
所以要用unsigned long long 运算,输出用 %llu
#include <cstdio>
#include <cstdlib>
#include<iostream>
#define N 10000
using namespace std;
typedef unsigned long long ll;
ll ModMul(ll a,ll b,ll n)//快速积取模 a*b%n
{
ll ans=;
while(b)
{
if(b&)
ans=(ans+a)%n;
a=(a+a)%n;
b>>=;
}
return ans;
}
ll ModExp(ll a,ll b,ll n)//快速幂取模 a^b%n
{
ll ans=;
while(b)
{
if(b&)
ans=ModMul(ans,a,n);
a=ModMul(a,a,n);
b>>=;
}
return ans;
}
bool miller_rabin(ll n)//Miller-Rabin素数检测算法
{
ll i,j,a,x,y,t,u,s=;
if(n==)
return true;
if(n<||!(n&))
return false;
for(t=,u=n-;!(u&);t++,u>>=);//n-1=u*2^t
for(i=;i<s;i++)
{
a=rand()%(n-)+;
x=ModExp(a,u,n);
for(j=;j<t;j++)
{
y=ModMul(x,x,n);
if(y==&&x!=&&x!=n-)
return false;
x=y;
}
if(x!=)
return false;
}
return true;
} int main()
{
ll n;
ll t;
scanf("%llu",&t);
while(t--)
{
scanf("%llu",&n); for(ll i=;i<N;i++)
if(miller_rabin(i)&&miller_rabin(n-i))
{
printf("%llu %llu\n",i,n-i);
break;
} }
return ;
}

Goldbach的更多相关文章

  1. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  2. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

  3. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

  4. HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)

    Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...

  5. Goldbach's Conjecture(哥德巴赫猜想)

    Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  6. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  7. POJ 2262 Goldbach&#39;s Conjecture(素数相关)

    POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...

  8. UVa 543 - Goldbach's Conjecture

    题目大意:给一个偶数,判断是否是两个素数的和. 先用sieve方法生成一个素数表,然后再进行判断即可. #include <cstdio> #include <vector> ...

  9. 【LightOJ1259】Goldbach`s Conjecture(数论)

    [LightOJ1259]Goldbach`s Conjecture(数论) 题面 Vjudge T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方 ...

  10. POJ 2262 Goldbach's Conjecture (打表)

    题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...

随机推荐

  1. PyTorch在NLP任务中使用预训练词向量

    在使用pytorch或tensorflow等神经网络框架进行nlp任务的处理时,可以通过对应的Embedding层做词向量的处理,更多的时候,使用预训练好的词向量会带来更优的性能.下面分别介绍使用ge ...

  2. JSONP 跨域请求 - 获取JSON数据

    如何用原生方式使用JSONP? 下边这一DEMO实际上是JSONP的简单表现形式,在客户端声明回调函数之后,客户端通过script标签向服务器跨域请求数据,然后服务端返回相应的数据并动态执行回调函数. ...

  3. WINDOWS-API:API函数大全

    操作系统除了协调应用程序的执行.内存分配.系统资源管理外,同时也是一个很大的服务中心,调用这个服务中心的各种服务(每一种服务是一个函数),可以帮肋应用程序达到开启视窗.描绘图形.使用周边设备的目的,由 ...

  4. 国庆集训 || Wannafly Day1

    网址:https://www.nowcoder.com/acm/contest/201#question A.签到 手速石头剪刀布 #include <cstdio> #include & ...

  5. shell脚本,awk数组之如何处理多个文件。

    [root@localhost | > file [root@localhost - | > file1 [root@localhost awk]# cat file [root@loca ...

  6. (1) zabbix进程构成

    进程介绍 zabbix_agentd客户端守护进程,此进程收集客户端数据,例如cpu负载.内存.硬盘使用情况等 zabbix_getzabbix工具,单独使用的命令,通常在server或者proxy端 ...

  7. [图文][提供可行性脚本] CentOS 7 Fencing+Pacemaker三节点搭建高可用集群

    实验说明: 实验环境: 宿主机系统   :Fedora 28 WorkStation 虚拟机管理器 :Virt-Manager 1.5.1 虚拟机配置   :ha1  CentOS 7.2 1511 ...

  8. 《offline coolbook》笔记

    https://jakearchibald.com/2014/offline-cookbook/ 在install中对依赖进行缓存 self.addEventListener('install', f ...

  9. clipboard 在 vue 中的使用

    简介 页面中用 clipboard 可以进行复制粘贴,clipboard能将内容直接写入剪切板 安装 npm install --save clipboard 使用方法一 <template&g ...

  10. php各种主流框架的优缺点总结

    ThinkPHP ThinkPHP(FCS)是一个轻量级的中型框架,是从Java的Struts结构移植过来的中文PHP开发框架.它使用面向对象的开发结构和MVC模式,并且模拟实现了Struts的标签库 ...