题目链接: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 ;
}

计蒜客 Goldbach Miller_Rabin判别法(大素数判别法)的更多相关文章

  1. 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)

    若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...

  2. 计蒜客——Goldbach

    Goldbach 判断大素数 #include<cstdio> #include<cstdlib> using namespace std; #define N 10000 t ...

  3. 计蒜客模拟赛5 D2T1 成绩统计

    又到了一年一度的新生入学季了,清华和北大的计算机系同学都参加了同一场开学考试(因为两校兄弟情谊深厚嘛,来一场联考还是很正常的). 不幸的是,正当老师要统计大家的成绩时,世界上的所有计算机全部瘫痪了. ...

  4. 计蒜客 等边三角形 dfs

    题目: https://www.jisuanke.com/course/2291/182238 思路: 1.dfs(int a,int b,int c,int index)//a,b,c三条边的边长, ...

  5. 计蒜客:Entertainment Box

    Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fight ...

  6. 计蒜客 31436 - 提高水平 - [状压DP]

    题目链接:https://nanti.jisuanke.com/t/31436 作为一名车手,为了提高自身的姿势水平,平时的练习是必不可少的.小 J 每天的训练包含 $N$ 个训练项目,他会按照某个顺 ...

  7. 计蒜客 31434 - 广场车神 - [DP+前缀和]

    题目链接:https://nanti.jisuanke.com/t/31434 小 D 是一位著名的车手,他热衷于在广场上飙车.每年儿童节过后,小 D 都会在广场上举行一场别样的车技大赛. 小 D 所 ...

  8. 运用NP求解 “跳跃游戏”---计蒜客

    计蒜客里面有一道“跳跃游戏的问题” 给定一个非负整数数组,假定你的初始位置为数组第一个下标. 数组中的每个元素代表你在那个位置能够跳跃的最大长度. 你的目标是到达最后一个下标,并且使用最少的跳跃次数. ...

  9. 计蒜客 作弊揭发者(string的应用)

    鉴于我市拥堵的交通状况,市政交管部门经过听证决定在道路两侧安置自动停车收费系统.当车辆驶入车位,系统会通过配有的摄像头拍摄车辆画面,通过识别车牌上的数字.字母序列识别车牌,通过连接车管所车辆信息数据库 ...

随机推荐

  1. iOS开发libz.dylib介绍

    libz.dylib这个Xcode系统库文件经常用到.这个其实是个动态链接库. 后缀名为.dylib的文件是一个动态库,这个库是运行时加载而不是编译时加载.这个也说明了obj-C是运行时语言,也就是数 ...

  2. SQL 跨库查询

    使用SQL查询数据,不仅能查询当前库的数据,还可以跨数据库,甚至跨服务器查询. 下面给大家介绍一下跨服务器查询的步骤(以SQL Server为例): 1,建立数据库链接 EXEC sp_addlink ...

  3. 导入导出SQL数据库

    在需要导出的数据库名上右键,选择转储SQL-数据和结构 在需要导入的连接中新建相同名称的数据库,右键选择运行SQL文件,即可将数据库数据转储到新的数据库中

  4. Android------去除标题栏

    这里暂时只给出一种方法,在java代码中去除 1.继承Activity 在onCreate方法中 getWindow().setFlags(WindowManager.LayoutParams.FLA ...

  5. mysql 重置 root 密码

    mysqld_safe --skip-grant-tables & UPDATE mysql.user SET authentication_string=PASSWORD('mima') W ...

  6. WPF 分页控件的实现 -用户控件

    效果图:

  7. 【bzoj2100】[Usaco2010 Dec]Apple Delivery 最短路

    题目描述 Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she tr ...

  8. BZOJ4237 稻草人(分治+树状数组+单调栈)

    如果要询问的某个纵坐标为inf的点左边是否有点能与其构成所要求的矩形,只要用个单调栈就可以了.可以想到用分治来制造单调性. 按横坐标排序,每次考虑跨过分治中心的矩形.考虑右边的每个点能与左边的哪些点构 ...

  9. Android SDK Manager下载,解决方案

    一.Windows 平台 在C:\Windows\System32\drivers\etc\hosts文件.添加一行:74.125.237.1       dl-ssl.google.com 二.Li ...

  10. NOIP 2018 -The Wound-

    "一招不慎,满盘皆输" 如果这个盘是整整一年的OI生涯的话 那么"一招"一定就是NOIP了 Update 2019/4/6 剧变的一年 noip这个成绩意味着我 ...