Questions tagged [euclidean-algorithm]

The Euclidean algorithm (aka Euclid's Algorithm) is an efficient method for computing the greatest common divisor (GCD) of two integers (numbers), the largest number that divides them both without a remainder.

The Euclidean algorithm (aka Euclid's Algorithm) is an efficient method for computing the greatest common divisor (GCD) of two integers (numbers), the largest number that divides them both without a remainder.

26 questions
4
votes
3 answers

Is this some kind of morphism in the recursion-schemes?

I implemented Euclid's algorithm in the following way at first. euclid x 0 = x euclid x y = euclid y (x `mod` y) The algorithm is tail-recursion, and I expect that it can be intuitively written with recursion-schemes. Then, the following euc is an…
4
votes
2 answers

Is it possible to implement the extended euclidean algorithm with unsigned machine words?

I'm trying to find a way to implement EEA using uint64_t in C, on a system that will not support 128-bit integers. The problem is that it seems like there is always a case where some variable or another will overflow, generating incorrect…
BadZen
  • 4,083
  • 2
  • 25
  • 48
1
vote
1 answer

How to write python code to plot the process of the Euclidean algorithm on a rectangle

I am a new coder and want to write some code to plot various rectangles in matplotlib, taking the animation from this link to demonstrate continued fractions. Namely, I am trying to write a function that takes the width and height of a rectangle and…
1
vote
0 answers

Unnormalizing in Knuth's Algorithm D

I'm trying to implement Algorithm D from Knuth's "The Art of Computer Programming, Vol 2" in Rust although I'm having trouble understating how to implement the very last step of unnormalizing. My natural numbers are a class where each number is a…
beeclu
  • 11
  • 1
1
vote
0 answers

how do we know the L = 4n^2 in euclidean TSP algorithm?

I am trying to understand the euclidean TSP algorithm. From most of the explanations available online, we set the value of L = 4n^2. is there any explanation for why L has that value? Here is the link to the…
1
vote
4 answers

Compute Euclidian distance in 100 dimensions between many points: how to be fast?

I have a Pandas DataFrame of 2 million entries Each entry is a point in a 100 dimensional space I want to compute the Euclidian distance between the N last points and all the others to find the closest neighbors (to simplify let's say find the…
Vincent
  • 153
  • 1
  • 1
  • 6
1
vote
1 answer

Evaluating implementation of Extended Euclidean algorithm

After some experimentation and search, I came up with the following definition: emcd' :: Integer -> Integer -> (Integer,Integer,Integer) emcd' a 0 = (a, 1, 0) emcd' a b = let (g, t, s) = emcd' b r in (g, s, t - (q * s)) where (q, r) =…
F. Zer
  • 1,081
  • 7
  • 9
1
vote
0 answers

Question about the Extended Euclidean Algorithm

So about the Extended Euclidean algorithm, the algorithm that finds, a, b, and d in the equation am+bn=d, where m and n are two positive integers, d is their GCD, and a and b are two integers (not necessarily positive) So the book I am following has…
Prithvidiamond
  • 327
  • 2
  • 15
1
vote
1 answer

BigInteger Extended Euclidean Algorithm recursion error

I am trying to make an extended euclidean algorithm with the BigInteger. but I am keeping getting the error that Exception in thread "main" java.lang.ArithmeticException: BigInteger divide by zero I searched on google and it says that I might get an…
1
vote
1 answer

Is there any way to perform this type of recursion in C++ or python?

Let us say I have a function called my_func(a,b,s,t). Suppose, I want a and b to be passed by value, but I want s and t to be passed by reference. As in, I want to some how pass in let us say (4,5,s',t'). The function performs computations by…
1
vote
1 answer

Implement modInverse using Extended Euclid Algorithm in Java

modInverse method of class BigInteger should not be used. I tried and used this method but it does not produce the correct result. Any help would be appreciated. public static int[] extendedgcd(int a, int b) { if (b==0) { return…
swishy
  • 21
  • 1
1
vote
1 answer

Time Complexity of Euclid Algorithm by Subtraction

int gcd(int a, int b) { while(a!=b) { if(a > b) a = a - b; else b = b - a; } return a; } What is the time complexity of this algorithm? Can someone provide a detailed explanation?
sara112
  • 13
  • 2
1
vote
1 answer

How we can find GCD(k + a, k + b) if we already know the GCD(a, b)?

I was wondering if its possible in constant time to calculate the above mentioned goal. I need it to solve a problem on codechef.
0
votes
1 answer

Trying to write a code to findout how many times a function has been called upon

I have a two part Question where the first part was to write a code using the Euclidean algorithm function for two numbers. This was the code i made, it works: from math import * def Euclidean_algorithm(a, b, verbose = True): if a < b: …
Spuddy
  • 19
  • 4
0
votes
0 answers

Public key generator in Python (SECP256K1 elliptic curve cryptography)

I am currently new in Python and cryptography. I am trying to make a public key of SECP256K1 elliptic curve manually(without related library use), from a random generated private key as I learned. The method of generating private key is free. What…
1
2