本文主要是介绍Goldbach 米勒 罗宾算法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.来源:https://blog.csdn.net/qq_38749759/article/details/80042527
2.算数检测法介绍:https://blog.csdn.net/zengaming/article/details/51867240
3.米勒 罗宾算法原理介绍:https://blog.csdn.net/fisher_jiang/article/details/986654
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define LL unsigned long long//注意这个longlong的定义,必须有 unsigned
using namespace std;
LL prime[6] = {2, 3, 5, 233, 331};
LL qu(LL x, LL y, LL mod)
{LL ret = 0;while(y) {if(y & 1)ret = (ret + x) % mod;x = x * 2 % mod;y >>= 1;}return ret;
}
LL qpow(LL a, LL n, LL mod){LL ret = 1;while(n) {if(n & 1) ret = qu(ret, a, mod);a = qu(a, a, mod);n >>= 1;}return ret;
}
bool MR(LL p)
{if(p < 2) return 0;if(p != 2 && p % 2 == 0) return 0;LL s = p - 1;while(! (s & 1)) s >>= 1;for(int i = 0; i < 5; ++i){if(p == prime[i]) return 1;LL t = s, m = qpow(prime[i], s, p);while(t != p - 1 && m != 1 && m != p - 1) {m = qu(m, m, p);t <<= 1;}if(m != p - 1 && !(t & 1)) return 0;}return 1;
}int main()
{LL p;int t;cin>>t;while (t){cin>>p;if(MR(p-2) ) {cout<<"2"<< " "<<p-2; continue;}for(LL i=3;i<=p/2;i+=2){if (MR(i) )if(MR(p-i)){cout<<i<<" "<<p-i<<endl;break;}}t--;}return 0;
}package javasishuyan;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {public static void main(String[] args) {Scanner scan=new Scanner(System.in);int num=scan.nextInt();BigInteger a,k;for(int i=0;i<num;i++){a=scan.nextBigInteger();for(k=BigInteger.valueOf(2);k.compareTo(a)<0;k=k.add(BigInteger.ONE)){if(IsSushu(k)&&IsSushu(a.subtract(k))){System.out.println(k+" "+a.subtract(k));break;}}}}public static boolean IsSushu(BigInteger a){if(a.isProbablePrime(10)){return true;}else{return false;}}
}1.还是java好理解,现在才知道java还给大数提供了专门的判断素数的方法:isProbablePrime(10)2.还有就是java 中大数累加,用k=k.add(BigInteger.ONE),ONE就表示1的意思。
这篇关于Goldbach 米勒 罗宾算法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!