题目链接: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. 好记性不如烂笔头之Maven使用小记

    一.前言 说起Maven,是在我上上东家接触的,掌握的还不错,因为种种原因,上家公司没有使用太多大众技术,我也没有太多施展的机会,对于以前掌握的技术,很多都荒废了,最近使用起来发现有点儿吃力了,为了加 ...

  2. BZOJ4835 遗忘之树

    点分树上的某个点和其某个子树在原树中的连接方式一般来说可以是由该点连向子树内任意一点,这样方案数即为所有子树大小之积.但有一种特殊情况是连接某点后导致编号最小的重心更换,只要去掉这种就行了,具体地可以 ...

  3. BZOJ4028 HEOI2015公约数数列(分块)

    前缀gcd的变化次数是log的,考虑对每一种gcd查询,问题变为查询一段区间是否存在异或前缀和=x/gcd. 无修改的话显然可以可持久化trie,但这玩意实在没法支持修改.于是考虑分块. 对于每一块将 ...

  4. [NOIP2016 TG D2T3]愤怒的小鸟

    题目大意:有一架弹弓位于(0,0)处,每次可以用它向第一象限发射一只小鸟,飞行轨迹均为形如y=ax2+bxy=ax+bx2 y=ax2+bx的曲线,且必须满足a<0(即是下开口的) 平面的第一象 ...

  5. BZOJ3864 & HDU4899:Hero meet devil——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3864 http://acm.hdu.edu.cn/showproblem.php?pid=4899 ...

  6. BZOJ1149:[CTSC/APIO2007]风铃——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=1149 https://www.luogu.org/problemnew/show/P3621 sb ...

  7. HDU1561:The more, The Better——题解

    http://acm.hdu.edu.cn/showproblem.php?pid=1561 ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允 ...

  8. [Ahoi2005]COMMON 约数研究 【欧拉线性筛的应用】

    1968: [Ahoi2005]COMMON 约数研究 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 2939  Solved: 2169 [Submi ...

  9. iOS更改项目名称的详细步骤

    http://www.cocoachina.com/ios/20150104/10824.html

  10. 题解【luoguP1525 NOIp提高组2010 关押罪犯】

    题目链接 题解 算法: 一个经典的并查集 但是需要用一点贪心的思想 做法: 先将给的冲突们按冲突值从大到小进行排序(这很显然) 然后一个一个的遍历它们 如果发现其中的一个冲突里的两个人在同一个集合里, ...