29 questions
2
votes
1
answer
379
views
What is the algorithm behind math.gcd and why it is faster Euclidean algorithm?
Tests shows that Python's math.gcd is one order faster than naive Euclidean algorithm implementation:
import math
from timeit import default_timer as timer
def gcd(a,b):
while b != 0:
...
1
vote
1
answer
71
views
optimization for euclidean alghorithm c++
The Euclidean algorithm works as follows:
1.Let a, b be the numbers whose GCD needs to be found.
2.If b = 0, then the number A is the desired GCD.
3.If b > a, then swap the numbers a and b.
4....
0
votes
2
answers
199
views
Prove of Euclid's algorithm of successive subtraction for the greatest common divisor
I know that succesive division approach is better in efficiency terms, but I am trying to prove that the substraction approach is also correct for any pair of integers and it will complete always in a ...
-1
votes
3
answers
84
views
Euclidean algorithm explanation?
Two inputs, number1 = 36 and number2 = 27, are passed to the following code for finding G.C.D of two numbers using Euclidean algorithm.
public static int euclideanAlgo(int number1, int number2){
...
2
votes
1
answer
124
views
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 ...
0
votes
1
answer
42
views
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 ...
0
votes
1
answer
1k
views
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 ...
0
votes
1
answer
93
views
Divide by zero, can't find the problem in this program which runs Euclid's algorithm to find the greatest common divisor
public static long[] simp (long [] a) {
long c = a[0];
long d = a[1];
if ( a[0]<0 ) {
a[0] = -1*a[0];
}
if (a[1]>a[0]) {
long v = a[0];
a[0]=a[1];
...
3
votes
1
answer
1k
views
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 ...
0
votes
1
answer
161
views
I want to get two numbers as input and calculate all the possible differences in Python
When I give the input as 17, 19: I only get 17, 19, 2 but I expect all numbers below 19 to be given as output. Since we are dealing with primes we should get 1 as GCD.
This is my code:
a=[]
n=int(...
0
votes
1
answer
283
views
Can the Euclid algorithm be used to do Reed Solomon decoding for the more general case where b > 1 in WHP 031?
I have been attempting to understand how to decode the following RS(7,3) code (prim Poly = 1011, prim Elem = 2, b = 2) per the Euclid algo described in WHP 031 previously linked to on the wikipedia ...
0
votes
1
answer
738
views
Extended euclidean algorithm for negative numbers
How to correctly calculate the coefficients of the Bezout ratio for the case of negative numbers in the implementation of the extended euclidean algorithm? Here is my code:
#include <iostream>
#...
1
vote
0
answers
33
views
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 ...
0
votes
1
answer
64
views
GRC for N numbers issue with StackOverflowException
I'm trying to find GRC for N numbers. For example N = 4, so the 4 numbers is for example 199 199 -199 -199. And im getting StackOverflowException for those numbers. Why?
first input number of integers ...
0
votes
0
answers
118
views
Calculating euclidean distance in a matrix
I am trying to calculate the euclidean distance in a matrix in C, I saw a similar post and tried it on my own matrix but as it is different I do not know how to make it work. This is my code:
#include ...
0
votes
0
answers
365
views
Extended Euclidean algorithm with polynomials
I need to implement an extended Euclidean algorithm for polynomials to get coefficients of Bézout's identity. The problem is I'm struggling with the correct implementation of such a function. I've ...
2
votes
4
answers
692
views
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 ...
0
votes
0
answers
177
views
Python - Print steps of an extended euclidean algorithm
Here is the current extended euclidean algorithm I found online :
def euclideEtendu(bNombre, aModulo):
""" Algorithme d'Euclide étendu, permettant de connaître:
PGCD
...
1
vote
1
answer
544
views
Understanding 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'...
1
vote
1
answer
194
views
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'...
1
vote
0
answers
266
views
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 ...
1
vote
1
answer
439
views
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 ...
4
votes
3
answers
242
views
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 ...
1
vote
1
answer
120
views
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',...
1
vote
1
answer
251
views
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, ...
1
vote
1
answer
1k
views
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? ...
1
vote
1
answer
460
views
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.
5
votes
2
answers
1k
views
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 ...
0
votes
2
answers
369
views
Can anyone explain how this code works? GCD, Recursive, Euclidian algorithm
Can anyone help explain to me how this code works? I am trying to understand how recursion works and how to write it.
def gcdRecur(a, b):
'''
a, b: positive integers
returns: a positive integer, the ...