题目链接:https://nanti.jisuanke.com/t/25985

题目:

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的偶数即可表示为两个素数的和。运用Miller_Rabin判别法从n/2向两边遍历(由素数的分布可知这样时间复杂度更优)。
代码实现如下:
 #include <cstdio>
#include <ctime>
#include <cstdlib> typedef long long ll;
int t;
long long n; ll multi(ll a, ll b, ll mod) {
ll ret = ;
while(b) {
if(b & )
ret = ret + a;
if(ret >= mod)
ret -= mod; a = a + a;
if(a >= mod)
a -= mod;
b >>= ;
}
return ret;
}
ll quick_pow(ll a, ll b, ll mod) {
ll ret = ;
while(b) {
if(b & )
ret = multi(ret, a, mod);
a = multi(a, a, mod);
b >>= ;
}
return ret;
}
bool Miller_Rabin(ll n) {
ll u = n - , pre, x;
int i, j, k = ;
if(n == || n == || n == || n == || n == )
return true;
if(n == || (!(n % )) || (!(n % )) || (!(n % )) || (!(n % )) || (!(n % )))
return false;
for(; !(u & ); k++, u >>= );
srand(time(NULL));
for(i = ; i < ; i++) {
x = rand() % (n - ) + ;
x = quick_pow(x, u, n);
pre = x;
for(j = ; j < k; j++) {
x = multi(x, x, n);
if(x == && pre != && pre != (n - ))
return false;
pre = x;
}
if(x != )
return false;
}
return true;
} int main() {
scanf("%d", &t);
while(t--) {
scanf("%lld", &n);
long long k = n /;
if(Miller_Rabin(k)) {
printf("%lld %lld\n", k, k);
} else {
long long l = k - , r = k + ;
while(!Miller_Rabin(l) || !Miller_Rabin(r)) {
l--;
r++;
}
printf("%lld %lld\n", l, r);
}
}
return ;
}

最新文章

  1. MVVM架构~knockoutjs系列之正则表达式使规则更灵活
  2. ajax初探01
  3. poj 2337 有向图输出欧拉路径
  4. uva129 - Krypton Factor 7.4.3 困难的串
  5. android 开发 实现自动安装
  6. CFF前端沙龙总结
  7. C++中关于const的思考
  8. Windows提供了两种将DLL映像到进程地址空间的方法(隐式和显式)
  9. Manor
  10. Matlab中K-means聚类算法的使用(K-均值聚类)
  11. JS表单原生验证器
  12. Configure Always On Availability Group for SQL Server on RHEL——Red Hat Enterprise Linux上配置SQL Server Always On Availability Group
  13. 关于使用lombok遇到的问题
  14. 【轉】使用jQuery播放/暂停 HTML5视频
  15. vuejs通过filterBy,orderBy实现搜索筛选,降序排序数据实例
  16. 借助python工具从word文件中抽取相关表的定义,最后组装建表语句-非常好
  17. [LeetCode&amp;Python] Problem 455. Assign Cookies
  18. English trip -- MC(情景课)3 D
  19. c#中值类型和引用类型的区别
  20. [AirFlow]AirFlow使用指南三 第一个DAG示例

热门文章

  1. python学习笔记03:python的核心数据类型
  2. MFC加速键
  3. &lt;Android&gt;tab选项卡
  4. ASP.NET 最全的POST提交数据和接收数据 —— (1) 用url传参方式
  5. (转)Elasticsearch .net client NEST使用说明 2.x
  6. C# 压缩组件介绍与入门
  7. 解决爬虫浏览器中General显示 Status Code:304 NOT MODIFIED,而在requests请求时出现403被拦截的情况。
  8. Java序列简单使用
  9. 【bzoj1370】[Baltic2003]Gang团伙 并查集
  10. (沒有介紹標準算法的)RMQ問題