Home > Back-end >  A freshman urgent help, help me see the "goldbach conjecture" C
A freshman urgent help, help me see the "goldbach conjecture" C

Time:02-06

7-14 goldbach conjecture (10)
Goldbach conjecture are familiar, guess the statement for the euler's version of the common today, that any even number larger than 2 can be written as the sum of two prime Numbers, also known as the "strong goldbach conjecture" or "goldbach conjecture" about even, due to an even number may have multiple sets of different prime Numbers, so request output two primes the most close to each other.

Input format:
There are more lines in the input, each line has a accidentally integer n (5 & lt; N
=10000)
The output format:
For each number, the output of two primes the most close to each other, and is equal to the even number (primes smaller before the large prime Numbers).

Input the sample:
Given a set of input here, for example:

20
30
40
The output sample:
Here is given the corresponding output, for example:

July 13
13 17
17 of 23

CodePudding user response:

The even number divided by 2, then it is good to look for prime Numbers from the left and right sides

CodePudding user response:

CodePudding user response:

The
reference 1/f, Simple, Soft reply:
the even number divided by 2, then it is good to look for prime Numbers from the left and right sides
root should be open

CodePudding user response:

Reference:
 # include & lt; Iostream> 
#include
using namespace std;

Bool Prime (int n)
{
For (int I=2; I & lt;=SQRT (n); I++) {
If I (n %==0)
return false;
}
return true;
}

Int main ()
{
Int n [10000]={0}, j=0, k=0;
//while (cin & gt;> N [j], n [j] & gt; 5 & amp; & N [j] <=10000) j++;//input, when the input integer & lt;=5 or & gt; The end of 10000 when input
While (cin & gt;> N [j]) j++;//input, Ctrl + Z input end of the
While (kFor (int I=n [k]/2; I & gt;=2; I -) {
If (Prime (I) & amp; & N [k] - I) (Prime) {
Cout & lt; break;
}
}
K++;
}

return 0;
}

CodePudding user response:

refer to the second floor the wise know already should good karma response:
error code don't have reference value to the classmate don't have to see
Change or as a wrong topic
See who find more mistakes

CodePudding user response:

 const int MAX=20;//input number, most can modify 

Int isPrime (int a)
{
int n;//sign
For (int I=2; I & lt; a; I + +)
{
N=1;
If (a % I==0)//non prime
{
n=0;
break;
}
}
If (n==1)
return 1;
The else
return 0;
}

Int main ()
{
Int no [MAX]={0};//store data array
Int num.//the number of data
Int no_Mo;//data/2 find middle prime
Int n1, and n2;//output
Printf (" goldbach conjecture, the number of input data: \ n ");
scanf("%d",& Num);
Printf (" please input data (even) : \ n ");
For (int I=0; I & lt; Num. I++)
{
scanf("%d",& No [I]);
If (no [I] % 2==1)
{
Printf (" not even! \n");
break;
}
}
//printf (" % d ", no [0]).
For (int I=0; I & lt; Num. I++)
{
No_Mo=no [I]/2;
For (int j=no_Mo; J & gt; 0; J -)
{
If (isPrime (j)==1 & amp; & IsPrime (no [I] - j)==1)
{
N1=j;
N2=no [I] - j;
break;
}

}
Printf (" % 4 d % 4 d \ n ", n1, and n2);
}
return 0;
}

CodePudding user response:

The function must be implemented

CodePudding user response:

Prime there can be serious point, slowly adjust yourself
 int isPrime (int a) 
{
Int n=0;//sign
If (a==1)
return 1;
If (a==2)
return 0;
For (int I=2; I & lt; a; I + +)
{
N=1;
If (a % I==0)//non prime
{
n=0;
break;
}
}
If (n==1)
return 1;
The else
return 0;
}

CodePudding user response:

reference 5 floor lin5161678 reply:
Quote: refer to the second floor the wise know already should good karma response:
error code don't have reference value to the classmate don't have to see
Change or as a wrong topic
See who find more error


Haha, 90009 students always don't listen carefully in class, stop monkeying around small code ~
  • Related