Number theory [Miller_rabin] Goldbach

Source: Internet
Author: User

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 the primes.

The actual verification of the Goldbach conjecture shows that even numbers below at least 1e14 can be expressed as a sum O f The prime numbers.

Many times, there is more than one-to-represent even numbers as-prime numbers.

For example, 18=5+13=7+11, 64=3+61=5+59=11+53=17+47=23+41, etc.

Now this problem are asking you to divide a postive even an integer n (2<n<2^63) into the prime numbers.

Although a certain scope of the problem have not been strictly proved the correctness of Goldbach ' s conjecture, we still ho PE that can solve it.

If you find a even number of Goldbach conjectures is not true and then this question would be wrong, but we would like To congratulate the solving this math problem that have 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 of which is a postive even integer n (2<n<2^63).

Output:

The output is a also T lines, each of which is a number we asked for.

T is about 100.

The answer is not the only one, the answer is correct

Sample input
18
Sample output
3 5

Idea: Enumerate the two numbers divided by N, and determine whether they are prime numbers at the same time; How to determine whether a larger number (around 1e18) is prime: Miller_rabin algorithm
Note the range of values for some common data types:

unsigned int 0~4294967295
int-2147483648~2147483647
unsigned long 0~4294967295
long-2147483648~2147483647

The maximum value of long long: 9223372036854775807
The minimum value of long long:-9223372036854775808
Unsigned the maximum value of long long: 18446744073709551615

Maximum value of __int64:9223372036854775807
Minimum value of __int64:9223372036854775808
Maximum value of unsigned __int64:18446744073709551615

AC Code:
#include <iostream>#include<cstdio>#defineMAXN 100010typedef unsignedLong Longll//data is easy to explode in operation Long Longusing namespaceStd;ll qmull (ll a,ll b,ll N) {//Fast Productll ans=0;  while(b) {if(b&1) ans= (ans+a)%N; A= (a+a)%N; b=b>>1; }    returnans;} ll Qpow (ll a,ll b,ll N) {//Fast Powerll ret=1; llBase=a%N;  while(b) {if(b&1) Ret=qmull (ret,Base, N)%N; Base=qmull (Base,Base, N)%N; b>>=1; }    returnret;}BOOLMiller_rabin (ll N) {//miller_rabin Prime number testll pan[4]={2,3,7, One};  for(LL i=0; i<4; i++)if(Qpow (pan[i],n-1, n)! =1)return 0; return 1;}intMain () {ll t; scanf ("%llu",&t);  while(t--) {ll n; scanf ("%llu",&N);  for(LL i=2;; i++){         if(Miller_rabin (i) &&miller_rabin (n-i)) {printf ("%llu%llu\n", i,n-i); Break;} }    }    return 0;}

Number theory [Miller_rabin] Goldbach

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.