Goldbach
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的更多相关文章
- Goldbach's Conjecture
Goldbach's Conjecture Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
- Goldbach's Conjecture(哥德巴赫猜想)
Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- (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 ...
- POJ 2262 Goldbach's Conjecture(素数相关)
POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...
- UVa 543 - Goldbach's Conjecture
题目大意:给一个偶数,判断是否是两个素数的和. 先用sieve方法生成一个素数表,然后再进行判断即可. #include <cstdio> #include <vector> ...
- 【LightOJ1259】Goldbach`s Conjecture(数论)
[LightOJ1259]Goldbach`s Conjecture(数论) 题面 Vjudge T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方 ...
- POJ 2262 Goldbach's Conjecture (打表)
题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...
随机推荐
- ARC和MRC混合模式下的编译问题
在一个支持ARC (Automatic Reference Counting)的项目中,有时候需要禁止其中几个文件使用ARC模式编译(比如你用了第三方不支持ARC的类库).这时就要点击工程文件,在ta ...
- java 核心技术卷一笔记 6 .1接口 lambda 表达式 内部类
6.1 接口不是类,是对类的一组需求的描述,这些类需要遵守接口描述的统一格式进行定义.例如:Arrays类中sort方法(可以对对象数组进行排序)前提是对象所属的类必须实现了Comparable 接口 ...
- 编写shellcode的几种姿势
今天开始在做hitcon-training的题目,做到lab2就发现了自己的知识盲区,遇到无法执行shell的情况,需要自己打shellcode执行cat flag 操作 经过一系列的搜索,发现了几种 ...
- PAT (Basic Level) Practise (中文)-1035. 插入与归并(25)
PAT (Basic Level) Practise (中文)-1035. 插入与归并(25) http://www.patest.cn/contests/pat-b-practise/1035 ...
- 各种排序算法(JS实现)
目录: 直接插入排序.希尔排序.简单选择排序.堆排序.冒泡排序.快速排序,归并排序.桶排序.基数排序.多关键字排序.总结 JS测试代码 function genArr(){ let n = Math. ...
- Safari不能保存session的处理方法
在vue单页应用项目中,safari浏览器验证码登陆提示'验证码过期'或者验证码校验不通过的问题 原因:验证码存储在了session里,接着验证时又发起了一次会话,因为Safari不保存cookie, ...
- CSS3的背景background
CSS3中的Background属性 background: background-image || background-position/background-size || background ...
- mysql主从复制延时判断+脚本检查
在生产环境中,主从复制常常会有复制延迟的现象,主要是master是并发的写,而slave是单线程的应用relay log,所以会出现复制延时,在MySQL 5.6版本中有了基于库的多线程复制.还有Ma ...
- SQL SERVER 占用资源高的SQL语句
--SQL SERVER 占用资源高的SQL语句: --查询占用cpu高的前 50 个 SQL 语句 SELECT total_cpu_time,[total_physical_Reads], tot ...
- .NET中常见的加解密方式
在互联网普及的初期,人们更关注单纯的连接性,以不受任何限制地建立互联网为最终目的.正如事情都具有两面性,互联网的便捷性给人们带来了负面问题,计算机病毒的侵害.信息泄露.网络欺诈等利用互联网的犯罪行为日 ...