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. POJ Washing Clothes 洗衣服 (01背包,微变型)

    题意:有多种颜色的衣服,由两个人合作来洗,必须洗完一种颜色才能洗下一种,求需要多少时间能洗完. 思路:将衣服按颜色分类,对每种颜色进行01背包,容量上限是该种颜色衣服全部洗完的耗时长一半,其实就是在最 ...

  2. js设置元素float的问题

    用js设置一个元素的float样式 div.style.float = 'left'; 这句话在谷歌浏览器或许没问题,但是在IE,火狐下会无效 正确写法是 div.style.styleFloat = ...

  3. 2006: C语言实验——拍皮球

    2006: C语言实验——拍皮球 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 231  Solved: 162[Submit][Status][Web ...

  4. 快学UiAutomator创建第一个实例

    工具准备 一.准备好java环境(JDK)和安卓环境(SDK.ADT)jdk1.6+ \eclipse\SDK \ADT详情百度,安装java环境 二.打开eclipse 三.创建步骤: 右键新建== ...

  5. Caused by: java.lang.ClassNotFoundException: java.com.bj186.ssm.controller.UserController

    在搭建SpringMVC的时候,遇到的这个问题真的很奇葩, 找不到UserController这个类 这明明不就在工程目录下吗? 经过了一番艰苦卓绝的斗争, 才发现原来是包导少了 之前导入的包是: & ...

  6. Delphi 中内存映射对于大文件的使用

    这篇文章主要介绍了Delphi 中内存映射对于大文件的使用的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下 Delphi 中内存映射对于大文件的使用 平时很少使用大文件的内存映射,碰巧遇到了 ...

  7. Bootstrap历练实例:分页状态

    分页的状态 下面的实例演示了上表中所讨论的 class .disabled..active 的用法: <!DOCTYPE html><html><head>< ...

  8. java集合测试类等

    package demo.mytest; import java.lang.ref.SoftReference;import java.lang.ref.WeakReference;import ja ...

  9. percona-server-5.7二进制安装(tokudb)

    1.下载二进制安装包(适用于红帽.centos) https://www.percona.com/downloads/Percona-Server-LATEST/Percona-Server-5.7. ...

  10. MySQL 查询优化之 Index Condition Pushdown

    MySQL 查询优化之 Index Condition Pushdown Index Condition Pushdown限制条件 Index Condition Pushdown工作原理 ICP的开 ...