gcd = 1 when no common numbers [closed] - math

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
16 (which has a prime decomposition of 2^4) and 27 (which has a prime decomposition of 3^3) have no common prime factors. Then why is the result of gcd(16, 27) == 1?
I've checked with Python:
>>> from fractions import gcd
>>> gcd(16, 27)
1

What you are probably confusing with is that the numbers 16 and 27 don't have any common divisors except 1. GCD is defined as the greatest common divisor/factor which divides both the numbers.
You are probably thinking about co-primes! But, neither 16 or 27 is prime to be checked for co-prime, as only prime numbers are compared for co-prime condition!
As you can see, the factors (divisors) of 16 are 1,2,4,8,16. Similarly, the factors (divisors) of 27 are 1,3,9,27.
16---> 1,2,4,8,16
27---> 1,3,9,27.
So, checking the highest/greatest common factor(h/gcf) OR greatest common divisor(gcd) of both the numbers, we find the gcd to be 1.
Hence, your python script is giving you the correct result as really the gcd of 16 and 27 does come out to be 1 as I explained above!

Related

Linear Programming - Absolute value greater than a constant [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
How would you convert the constraint |x| >= 2 so that it would work in a Linear Program (in particular, solving using Simplex).
I understand how to convert |x| <= 2 as that would become x <= 2 and -x <= 2
However the same logic does not work when you have a minimum constant.
There is just no way to shoehorn an equation like |x|>=2 into a pure (continuous) LP. You need to formulate x <= -2 OR x >= 2 which is non-convex. This will require a binary variable making the problem a MIP.
One formulation can be:
x >= 2 - delta*M
x <= -2 + (1-delta)*M
delta in {0,1}
where M is judiciously chosen large number. E.g. if -100<=x<=100 then you can choose M=102.

How does using log10 correctly calculate the length of a integer? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
int length = (int) floor( log10 (float) number ) + 1;
My question is essentially a math question: WHY does taking the log10() of a number, flooring that number, adding 1, and then casting it into an int correctly calculate the length of number?
I really want to know the deep mathematical explanation please!
For an integer number that has n digits, it's value is between 10^(n - 1)(included) and 10^n, and so log10(number) is between n - 1(included) and n. Then the function floor cuts down the fractional part, leaves the result as n - 1. Finally, adding 1 to it gives the number of digits.
Consider that a four-digit number x is somewhere between 1000 <= x < 10000. Taking the log base 10 of all three components gives 3.000 <= log(x, 10) < 4.000. Taking the floor (or int) of each component and adding one gives 4 <= int(log(x, 10))+1 <= 4.
Ignoring round-off error, this gives you the number of digits in x.

Number Theory - Factors, HCF and LCM [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
30, 40 and 'n' are such that every number is a factor of the product of other 2 number. If 'n' is a positive
integer , what is the difference between the maximum value of 'n' and the minimum value of 'n'?
Now, since it says that n is a factor of the product of the other 2 numbers, the max value that n can take is 1200 right?
i guess the hcf will give the minimum value of n
Listing the factors of 30 and 40
30 -> 1,2,3,5,6,10,15,30
40 -> 1,2,4,5,8,10,20,40
hcf(30,40) -> 10
Therfore, the difference is 1200-10 => 1190..
But the answer that is given is 1188...where am i going wrong?
Your approach is wrong. The greatest common divisor of 30 and 40 is not your smallest n.
You are looking for the smallest integer n > 0 that satisfies 40*n = 0 (mod 30) and 30*n = 0 (mod 40).
For the first equation, the result is n_1 = 3. For the second equation, we get n_2 = 4. The smallest n to satisfy both equations is the least common multiple of n_1 and n_2 -- in this case, n = 12.
hcf(30,40) -> 12
30=2*3*5
40=2*2*2*5
So, hcf(30,40) -> 3*2*2=12

Probability of n-bit integers [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
random a 512-bit integer N that is not a multiple of 2, 3, or 5
I have a question
for a random 512-bit integer n that isn't a multiple of 2,3, or 5 what is the chance that n is prime? what about that n is composite but fools the fermat primality test? what about that it is composite but doesn't fool the fermat primality test?
Since this is definitely a homework problem, I'll point you at the Prime Number Theorem, which should give you the probability that any large number is prime.
From there, modify the probability with your new information about composite numbers that have been eliminated (Hint: Think about how the problem space shrinks).
Best of luck!

primes and logarithms [theory] [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 12 years ago.
Improve this question
I know this is not a mathematical forum but given the bright minds that participate here, i am sure that this question is of interest nevertheless. How would you develop and explain the following statement:
"we can convert the product of a set
of primes into a sum of the logarithms
of the primes by applying logarithms
to both parts of this conjecture"
log(a * b) = log(a) + log(b)
thanks for that OrangeDog and John!
re benefit of introducing logs, OrangeDog is right indeed. It is specific to an exercise from an MIT OpenCourse class. Here's the full details:
There is a cute result from number
theory that states that for
sufficiently large n the product of
the primes less than n is less than or
equal to e^n and that as n grows,
this becomes a tight bound (that is,
the ratio of the product of the primes
to e^n gets close to 1 as n grows).
Computing a product of a large number
of prime numbers can result in a very
large number, which can potentially
cause problems with our computation.
[note: this is what John was referring
to] So we can convert the product of a
set of primes into a sum of the
logarithms of the primes by applying
logarithms to both parts of this
conjecture. In this case, the
conjecture above reduces to the claim
that the sum of the logarithms of all
the primes less than n is less than n,
and that as n grows, the ratio of this
sum to n gets close to 1.
EDIT
given these statements i am, however, unsure about how to apply them i.e.
how do we go from here:
2 x 3 x 5 <= e^7
to
"applying
logarithms to both parts of this
conjecture."
EDIT 2
got it...
2 x 3 x 5 <= e^7
knowing that logarithms are the opposite of powers we can say:
log(2x3x5) <= 7
which is also the same as:
log(2)+log(3)+log(5) <= 7
this only starts to show its "value" when n (in this case 7) gets larger i.e. the 1000th prime or higher

Resources