greatest-common-divisor Questions
7
Solved
Can someone give an example for finding greatest common divisor algorithm for more than two numbers?
I believe programming language doesn't matter.
Illiquid asked 5/8, 2009 at 7:49
5
Solved
So I'm trying to learn R and using a number of resources including a book called "Discovering Statistics using R" and a bunch of other cool eBooks.
I understand a great method in programming is th...
Spinnaker asked 1/2, 2014 at 18:59
2
Solved
I can't figure out what Knuth meant in his instructions for an exercise 8 from Chapter 1.1.
The task is to make an efficient gcd algorithm of two positive integers m and n using his notation thet...
Tucana asked 4/11, 2014 at 18:39
3
Solved
I'm using the fractions module in Python v3.1 to compute the greatest common divisor. I would like to know what algorithm is used. I'm guessing the Euclidean method, but would like to be sure. The ...
Stedman asked 3/6, 2010 at 0:43
11
Solved
So I'm writing a program in Python to get the GCD of any amount of numbers.
def GCD(numbers):
if numbers[-1] == 0:
return numbers[0]
# i'm stuck here, this is wrong
for i in range(len(numbe...
Utimer asked 18/5, 2013 at 19:19
2
Modular inverses can be computed as follows (from Rosetta Code):
#include <stdio.h>
int mul_inv(int a, int b)
{
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a >...
Ebonee asked 30/11, 2018 at 15:22
2
Solved
From this question Java: get greatest common divisor
In getting the gcd of any data type whether int, long, Integer, Long, which answer is better in terms of precision, speed, cpu usage, etc.?
A:...
Tesler asked 5/2, 2014 at 7:16
2
Solved
clang and GCC have a int __builtin_ctz(unsigned) function. This counts the trailing zeros in an integer. The Wikipedia article on this family of functions mentions that the binary GCD algorithm can...
Dent asked 26/8, 2020 at 19:57
12
I want to calculate gcd for a list of numbers.
But I don't know what's wrong with my code.
A = [12, 24, 27, 30, 36]
def Greatest_Common_Divisor(A):
for c in A:
while int(c) > 0:
if int(c) ...
Nester asked 22/3, 2015 at 12:51
13
Solved
What would be the easiest way to calculate Greatest Common Divisor and Least Common Multiple on a set of numbers? What math functions can be used to find this information?
Heretical asked 17/11, 2010 at 5:50
2
METHOD (A Juggling Algorithm)
Divide the array in different sets where number of sets is equal to GCD of n and d and move the elements within sets.
If GCD is 1 as is for the above example array (n ...
Orren asked 14/6, 2014 at 15:9
15
Solved
what is the fastest way to compute the greatest common divisor of n numbers?
Emmaline asked 3/2, 2011 at 11:26
4
Solved
I have written the following code for calculating the Greatest Common Divisor of two positive numbers. Are there some matters in the code which are not optimal or clojurian enough, and if so what w...
Polyphemus asked 3/9, 2015 at 21:55
8
Solved
I already have a function that finds the GCD of 2 numbers.
function getGCDBetween($a, $b)
{
while ($b != 0)
{
$m = $a % $b;
$a = $b;
$b = $m;
}
return $a;
}
But now, I would like to exten...
Ossification asked 11/12, 2012 at 20:30
1
Solved
Given an array of positive numbers. I want to split the array into 2 different subset(s) such that the sum of their gcd (greatest common divisor) is maximum.
Example array: {6,7,6,7}.
Answer: The...
Pinko asked 8/6, 2019 at 5:54
3
Solved
I decided to implement a program that can find the GCD of any two numbers (including non-integers) in TI-Basic. I've used this just fine in Java, so I know it works. It works just fine in TI-Basic,...
Gillard asked 24/9, 2012 at 20:35
16
Solved
I have seen that such a function exists for BigInteger, i.e. BigInteger#gcd. Are there other functions in Java which also work for other types (int, long or Integer)? It seems this would make sense...
Tessi asked 24/10, 2010 at 16:40
5
Solved
Does numpy have a gcd function somewhere in its structure of modules?
I'm aware of fractions.gcd but thought a numpy equivalent maybe potentially quicker and work better with numpy datatypes.
I h...
Ignatius asked 22/3, 2013 at 11:38
2
Solved
I want to calculate the least common multiple of an array of values, using Euclideans algorithm
I am using this pseudocode implementation: found on wikipedia
function gcd(a, b)
while b ≠ 0
t :...
Bouilli asked 1/11, 2017 at 3:14
5
Solved
I'm writing a mixed numeral class and need a quick and easy 'greatest common divisor' function. Can anyone give me the code or a link to the code?
Eade asked 8/6, 2012 at 22:4
3
I want to simplify a fraction in my application. The fraction is like,
x/y where x and y are integers.
I want to simplify the fraction to its simplest form.
Can anyone please give me hints how to ...
Birdlime asked 15/10, 2011 at 10:5
1
I'm trying to use java.math.BigInteger
for some exact integer matrix computations in which the scalar values get up to millions of digits.
I've noticed that some of the builtin BigInteger operation...
Porett asked 7/1, 2017 at 2:19
3
Solved
I currently use this code to find gcd and lcm
def gcd(a, b):
while b != 0:
a, b = b, a%b
return a
def lcm(a, b):
result = a*b/gcd(a,b)
return result
But what if I want to do this for a lis...
Alishiaalisia asked 10/1, 2012 at 16:15
4
Solved
How to find LCM of {1, 2, ..., n} where 0 < n < 10001 in fastest possible way. The one way is to calculate n! / gcd (1,2,.....,n) but this can be slow as number of testcases are t < 501 an...
Wergild asked 30/5, 2015 at 6:33
5
I just found this algorithm to compute the greatest common divisor in my lecture notes:
public static int gcd( int a, int b ) {
while (b != 0) {
final int r = a % b;
a = b;
b = r;
}
return a...
Pocketbook asked 14/5, 2011 at 23:59
1 Next >
© 2022 - 2024 — McMap. All rights reserved.