Home > Software engineering >  Turn to vb z1, z2 are prime Numbers
Turn to vb z1, z2 are prime Numbers

Time:12-22

Pray god to make up a function, input z1, z2, output z2,
Z2 can incremental step 1 until the z1 and z2 co-prime

CodePudding user response:

This is math problem, has nothing to do with VB,

Two number are co-prime, usable Euclidean division, and in addition, the first increase Z2 to an odd number (if it is an even number, add 1 first, then testing), increasing since 2, so we can speed up the Z2 become a process of prime Numbers, if Z2 for prime Numbers and is not equal to the Z1, two number must co-prime,

CodePudding user response:

Think about this problem
1 excuse me, is a simple solution to this problem, or trying to solve the problem of other intermediate steps, and if the intermediate steps, suggest to consider other method, judgment
Number two is not a simple question whether co-prime

2 if the simple solution to this problem, the core: determine whether the number two is relatively prime, but I can't

CodePudding user response:

Euclid trigger is not complicated, is to find the greatest common divisor of two, if the greatest common divisor is 1, known as co-prime,

For example, May 21 and 15 are co-prime, is actually quite division by yu,

21/15=1... 6
15/6=2... 3
Orange-red=2... 0 (divided)

21 and 15 is the greatest common divisor of 3, not co-prime,

Again, such as, May 28 and 15 are co-prime:

28/15=1... 13
15/13=1... 2
13/2=6... 1
2/1=2... 0 (divided)

28 and 15 greatest common divisor is 1, co-prime, in fact, in addition to the remainder is 1 can stop,

  • Related