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 ...
随机推荐
- ubuntu 14.04 安装npm
1. 安装 sudo apt install nodejs-legacy sudo apt install npm
- 数组、Math、JOSN总结
json对象: 1.数组有length属性[尽量使用for循环] 2.而json没有length属性[可以使用for...in...循环] 3.for in 不能遍历页面中的节点对象. for ( v ...
- urllib基础-构造请求对象,设置用户代理User-Agent
有的网页具有一些反爬机制,如:需要浏览器请求头中的User-Agent.User-Agent类似浏览器的身份证. 程序中不设置User-Agent.默认是Python-urllib/3.5.这样网站就 ...
- java web.xml被文件加载过程及加载顺序小结
web.xml加载过程(步骤): 1.启动WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> ...
- end和sep的使用方法
end: 默认是换行'\n',表示以什么结尾,比如以, | \n 等 方法: 默认end = '\n' a b c 如果end = ' ' a b c sep: 默认是空格' ' 表示两个字符之间用什 ...
- solr DIH 设置定时索引
1 web.xml中加入 web.xml所在目录 /opt/solr-7.7.1/server/solr-webapp/webapp/WEB-INF <listener> <list ...
- JavaScript注释
JavaScript注释有两种方式: 1.单行注释. 2.多行注释. 单行注释 单行注释以“//”开头. <script type="text/javascript"> ...
- PAT Basic 1044
1044 火星数字 火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly ...
- BZOJ 4504: K个串
题目大意: 求一个序列的第k大的子串和. 题解: 对于一个右端点找最优的左端点,扔进堆里. 每次取堆顶,将这个右端点可以选择的左端点的区间分成两段,扔进堆里,重复k次. 现在需要对于一个固定的右端点, ...
- js中的this关键字
this是Javascript语言的一个关键字它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用,下面分四种情况,详细讨论this的用法 this是Javascript语言的一个关键字. 它 ...