Goldbach's conjecture says that every positive even number greater than 2 is the sum of two prime numbers. Example: 28 = 5 + 23. It is one of the most famous facts in number theory that has not been proved to be correct in the general case. It has been numerically confirmed up to very large numbers (much larger than we can go with our Prolog system). Write a predicate to find the two prime numbers that sum up to a given even integer.
1
Expert's answer
2012-09-06T09:30:46-0400
#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; __int64 powInt(__int64 &a, int n) { __int64 res = 1; while (n) { & if (n&1) res*=a; & a*=a; & n>>=1; } return res; } bool Ferma (const int n,const __int64 k = 20)//ôóíêö³ÿ âèêîíóºòüñÿ ïðàâèëüíî, ïîêè íå áóäå ïåðåïîâíåííÿ òèï³â { if (n%2) { & srand(time(0)); & __int64 a, b; & for (int i=0 ; i<k ; ++i) & { & a=((rand()%(n-2))+1); & b=(powInt(a,n-1))%n; & if (b!=1) & return 1; & } & return 0; } else return 1; }
int main () { cout<<"Input the number \n"; int num; cin>>num; int numDtwo = num / 2 - 1; int numDone = num / 2 + 1; for (int i = 0 ; i < num / 2 ; i++) { & if (Ferma(numDone) == 0 && Ferma(numDtwo) == 0) { & cout << numDone << ' ' << numDtwo; & break; & } & numDtwo--; & numDone++; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment