On number a + b = n and lcm (a, b) = m

// This article reference https://blog.csdn.net/Shinaria/article/details/79049838

// part of the reference https://blog.csdn.net/acoolgiser/article/details/81188440

Topic is this:

Given two positive integers n and m, satisfying a condition of a proper and b:

1. a+b=n

2.lcm(a, b)=m

 

1 is a magic available gcd (a, b) == gcd (n, m)

Proof: provided gcd (a, b) = g

 

Then a = a '* g b = b' * g wherein a ', b' prime and without care about its size

So the relationship between lcm and gcd availability

   m=g * a' * b'

  n=g*(a' + b')  

Easy to prove that: a '* b' and (a '+ b') prime, since divisible by a '* + b', simultaneously divisible only a 'divisible and b', but they are coprime

So QED.

 

Also in solving the problem, need to use the sqrt function, when I did not seriously consider the root of a negative number is the case, think about this only when I read other people's code.

But in fact it is not necessary to consider, as sqrt function returns -nan (ind) when dealing with negative numbers  

nan is an abbreviation for "not a number", i.e. the number of results is not.

ind is indeterminate acronym, that is not what determines Yes.

The square root of a negative number, the negative logarithm of 0.0 divided by 0.0, 0.0 multiplied by infinity ∞, infinity divided by infinity ∞ ∞ and other errors will get it.

 

I found in the header file math.h's its function declaration _Check_return_ _CRT_JIT_INTRINSIC double __cdecl sqrt (_In_ double _X);

DETAILED not read, but can be known, and its return value is a parameter of type double

Then I tried it on vs2015

        int a = -4;
    printf("%lf\n", (double)sqrt((a)));
    printf("%lf\n", (double)sqrt(double(-4)));
    printf("%d\n", (double)sqrt(double(-4)));
    printf("%d", (int)sqrt(double(-4)));                

The results are:

-nan (in)
-nan (in)
0
-2147483648

I do not see why not int error, speculation is implicit conversion happens now, I do not understand this.

Well, that's it.

 

 

  

Guess you like

Origin www.cnblogs.com/asdfknjhu/p/12113411.html
B