Home > Back-end >  Consult recognize a problem
Consult recognize a problem

Time:11-19

What is the blue code principle, always look not to understand

CodePudding user response:

C=GCD (a, b);//c is the greatest common divisor of a and b, a and b can be divided exactly by
B=b/c;//b divided by the greatest common divisor, the remaining factor
If (c % b==0)//if the rest of the factors can be divided exactly by greatest common divisor

This logic is a little look not to understand,
=10 such as a, b=8, b all prime factors are 2, 3 or a 2? The program is running the output is No,
12, such as a=b=8, b all prime factors are 2, 3 or a 2? The program is run output is Yes,

If a contains all b repeatable prime factor, is whether can be divided exactly by b directly,
If you don't repeat the prime factors of a consists of b, b=b/c; B the rest of the prime factors, calculated

CodePudding user response:

This is easy to understand, you should know what is the greatest common divisor, is a/b all joint product of prime Numbers, if a contain b of prime Numbers, then the greatest common divisor must contain all the prime Numbers, b
B=b/c is the greatest common divisor of prime Numbers, the remainder of the decomposed prime, also in c, if no longer, you certainly do not conform to the requirements of
Such as 6 and 4, the greatest common divisor is 2, instead of into the program, if 4 to 10, was no,

But this program is a bit of a problem, the code is the premise of prime value no more than 2 to the power, such as the program will not be able to handle a=6 and b=8, but obviously the two number is in conformity with the title, but the program will judge to False.

CodePudding user response:

refer to the second floor Golden_Chen response:
this is easy to understand, you should understand what is the greatest common divisor, is a/b all joint product of prime Numbers, if contain b prime, then the greatest common divisor must contain all the prime Numbers, b
B=b/c is the greatest common divisor of prime Numbers, the remainder of the decomposed prime, also in c, if no longer, you certainly do not conform to the requirements of
Such as 6 and 4, the greatest common divisor is 2, instead of into the program, if 4 to 10, was no,

But this program is a bit of a problem, the code is the premise of prime value no more than 2 to the power, such as the program will not be able to handle a=6 and b=8, but obviously the two number is in conformity with the title, but the program will judge is False.

Wow thank you bosses!
  • Related