Finding the GCD of three numbers?Is it correct to write gcd(a,b) if a<b?Recursive RelationsExtended Euclidean Algorithm with negative numbers minimum non-negative solutionPairs comparisons between two listsapproximate greatest common divisorAlgorithm for finding pairs in a list.Condition on prime Factorizations of 2 relatively prime numbersIs there a way I could express gcd as a linear combination of two numbers in more than 1 way?How $gcd (s,t)=1$ implies $gcd(s-t,s+t) =1$?GCD algorithm with approximative factors

Why aren't there more Gauls like Obelix?

Was this cameo in Captain Marvel computer generated?

Are small insurances worth it?

ESPP--any reason not to go all in?

Limpar string com Regex

How do you make a gun that shoots melee weapons and/or swords?

How does a sound wave propagate?

Can I negotiate a patent idea for a raise, under French law?

Why restrict private health insurance?

Is there a logarithm base for which the logarithm becomes an identity function?

I am the person who abides by rules but breaks the rules . Who am I

What is better: yes / no radio, or simple checkbox?

How does learning spells work when leveling a multiclass character?

What do you call someone who likes to pick fights?

How to educate team mate to take screenshots for bugs with out unwanted stuff

Tabular environment - text vertically positions itself by bottom of tikz picture in adjacent cell

Use Mercury as quenching liquid for swords?

Is there a math expression equivalent to the conditional ternary operator?

Does the US political system, in principle, allow for a no-party system?

Mixed Feelings - What am I

Does an unused member variable take up memory?

Propulsion Systems

Is the differential, dp, exact or not?

3.5% Interest Student Loan or use all of my savings on Tuition?



Finding the GCD of three numbers?


Is it correct to write gcd(a,b) if a<b?Recursive RelationsExtended Euclidean Algorithm with negative numbers minimum non-negative solutionPairs comparisons between two listsapproximate greatest common divisorAlgorithm for finding pairs in a list.Condition on prime Factorizations of 2 relatively prime numbersIs there a way I could express gcd as a linear combination of two numbers in more than 1 way?How $gcd (s,t)=1$ implies $gcd(s-t,s+t) =1$?GCD algorithm with approximative factors













11












$begingroup$


I have found an algorithm called the Binary GCD/Stein Algorithm which takes two non-negative integers and finds the greatest common factor of the two.



What I am trying to do is take three numbers and find if each pair is relatively prime (where the GCD is one). For example, if I have non-negative variables a b and c, then:



a = 1
b = 1
c = 2


Would satisfy this because none of these numbers have a GCD that is larger than one. Using a variation of the Stein Algorithm in Java, I would like to be able to find the GCD of all three pairs of numbers (ab bc ac) with each side being able to go up to five, for the sake of simplicity.



Is there a way I could tweak the algorithm to compute the GCD of three numbers, or would I have to compute three groups of two pairs?



Thanks for any and all help.










share|cite|improve this question











$endgroup$











  • $begingroup$
    Please note, there is an example of the implementation of this algorithm, in Java, on the link above.
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:07










  • $begingroup$
    If you treat $gcd$ as an operator, much like addition or multiplication, it's commutative and associative.
    $endgroup$
    – J. M. is not a mathematician
    Dec 23 '11 at 18:17










  • $begingroup$
    you could call your gcd function twice $d=rm gcd(a,b)$, $e=rm gcd(d,c)$
    $endgroup$
    – yoyo
    Dec 23 '11 at 18:19










  • $begingroup$
    It may be commutative if I have two of the same number, but if the sides are 11,6,1, I don't see how they could be commutative. Maybe I am misunderstanding your comment?
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:20






  • 3




    $begingroup$
    $gcd(a,b,c) = gcd(gcd(a,b),c) = gcd(a,gcd(b,c))=gcd(gcd(a,c),b)$
    $endgroup$
    – Álvaro Lozano-Robledo
    Dec 23 '11 at 18:21















11












$begingroup$


I have found an algorithm called the Binary GCD/Stein Algorithm which takes two non-negative integers and finds the greatest common factor of the two.



What I am trying to do is take three numbers and find if each pair is relatively prime (where the GCD is one). For example, if I have non-negative variables a b and c, then:



a = 1
b = 1
c = 2


Would satisfy this because none of these numbers have a GCD that is larger than one. Using a variation of the Stein Algorithm in Java, I would like to be able to find the GCD of all three pairs of numbers (ab bc ac) with each side being able to go up to five, for the sake of simplicity.



Is there a way I could tweak the algorithm to compute the GCD of three numbers, or would I have to compute three groups of two pairs?



Thanks for any and all help.










share|cite|improve this question











$endgroup$











  • $begingroup$
    Please note, there is an example of the implementation of this algorithm, in Java, on the link above.
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:07










  • $begingroup$
    If you treat $gcd$ as an operator, much like addition or multiplication, it's commutative and associative.
    $endgroup$
    – J. M. is not a mathematician
    Dec 23 '11 at 18:17










  • $begingroup$
    you could call your gcd function twice $d=rm gcd(a,b)$, $e=rm gcd(d,c)$
    $endgroup$
    – yoyo
    Dec 23 '11 at 18:19










  • $begingroup$
    It may be commutative if I have two of the same number, but if the sides are 11,6,1, I don't see how they could be commutative. Maybe I am misunderstanding your comment?
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:20






  • 3




    $begingroup$
    $gcd(a,b,c) = gcd(gcd(a,b),c) = gcd(a,gcd(b,c))=gcd(gcd(a,c),b)$
    $endgroup$
    – Álvaro Lozano-Robledo
    Dec 23 '11 at 18:21













11












11








11


4



$begingroup$


I have found an algorithm called the Binary GCD/Stein Algorithm which takes two non-negative integers and finds the greatest common factor of the two.



What I am trying to do is take three numbers and find if each pair is relatively prime (where the GCD is one). For example, if I have non-negative variables a b and c, then:



a = 1
b = 1
c = 2


Would satisfy this because none of these numbers have a GCD that is larger than one. Using a variation of the Stein Algorithm in Java, I would like to be able to find the GCD of all three pairs of numbers (ab bc ac) with each side being able to go up to five, for the sake of simplicity.



Is there a way I could tweak the algorithm to compute the GCD of three numbers, or would I have to compute three groups of two pairs?



Thanks for any and all help.










share|cite|improve this question











$endgroup$




I have found an algorithm called the Binary GCD/Stein Algorithm which takes two non-negative integers and finds the greatest common factor of the two.



What I am trying to do is take three numbers and find if each pair is relatively prime (where the GCD is one). For example, if I have non-negative variables a b and c, then:



a = 1
b = 1
c = 2


Would satisfy this because none of these numbers have a GCD that is larger than one. Using a variation of the Stein Algorithm in Java, I would like to be able to find the GCD of all three pairs of numbers (ab bc ac) with each side being able to go up to five, for the sake of simplicity.



Is there a way I could tweak the algorithm to compute the GCD of three numbers, or would I have to compute three groups of two pairs?



Thanks for any and all help.







elementary-number-theory algorithms






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 23 '11 at 18:17









J. M. is not a mathematician

61.3k5152290




61.3k5152290










asked Dec 23 '11 at 18:06









nmagerkonmagerko

2752515




2752515











  • $begingroup$
    Please note, there is an example of the implementation of this algorithm, in Java, on the link above.
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:07










  • $begingroup$
    If you treat $gcd$ as an operator, much like addition or multiplication, it's commutative and associative.
    $endgroup$
    – J. M. is not a mathematician
    Dec 23 '11 at 18:17










  • $begingroup$
    you could call your gcd function twice $d=rm gcd(a,b)$, $e=rm gcd(d,c)$
    $endgroup$
    – yoyo
    Dec 23 '11 at 18:19










  • $begingroup$
    It may be commutative if I have two of the same number, but if the sides are 11,6,1, I don't see how they could be commutative. Maybe I am misunderstanding your comment?
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:20






  • 3




    $begingroup$
    $gcd(a,b,c) = gcd(gcd(a,b),c) = gcd(a,gcd(b,c))=gcd(gcd(a,c),b)$
    $endgroup$
    – Álvaro Lozano-Robledo
    Dec 23 '11 at 18:21
















  • $begingroup$
    Please note, there is an example of the implementation of this algorithm, in Java, on the link above.
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:07










  • $begingroup$
    If you treat $gcd$ as an operator, much like addition or multiplication, it's commutative and associative.
    $endgroup$
    – J. M. is not a mathematician
    Dec 23 '11 at 18:17










  • $begingroup$
    you could call your gcd function twice $d=rm gcd(a,b)$, $e=rm gcd(d,c)$
    $endgroup$
    – yoyo
    Dec 23 '11 at 18:19










  • $begingroup$
    It may be commutative if I have two of the same number, but if the sides are 11,6,1, I don't see how they could be commutative. Maybe I am misunderstanding your comment?
    $endgroup$
    – nmagerko
    Dec 23 '11 at 18:20






  • 3




    $begingroup$
    $gcd(a,b,c) = gcd(gcd(a,b),c) = gcd(a,gcd(b,c))=gcd(gcd(a,c),b)$
    $endgroup$
    – Álvaro Lozano-Robledo
    Dec 23 '11 at 18:21















$begingroup$
Please note, there is an example of the implementation of this algorithm, in Java, on the link above.
$endgroup$
– nmagerko
Dec 23 '11 at 18:07




$begingroup$
Please note, there is an example of the implementation of this algorithm, in Java, on the link above.
$endgroup$
– nmagerko
Dec 23 '11 at 18:07












$begingroup$
If you treat $gcd$ as an operator, much like addition or multiplication, it's commutative and associative.
$endgroup$
– J. M. is not a mathematician
Dec 23 '11 at 18:17




$begingroup$
If you treat $gcd$ as an operator, much like addition or multiplication, it's commutative and associative.
$endgroup$
– J. M. is not a mathematician
Dec 23 '11 at 18:17












$begingroup$
you could call your gcd function twice $d=rm gcd(a,b)$, $e=rm gcd(d,c)$
$endgroup$
– yoyo
Dec 23 '11 at 18:19




$begingroup$
you could call your gcd function twice $d=rm gcd(a,b)$, $e=rm gcd(d,c)$
$endgroup$
– yoyo
Dec 23 '11 at 18:19












$begingroup$
It may be commutative if I have two of the same number, but if the sides are 11,6,1, I don't see how they could be commutative. Maybe I am misunderstanding your comment?
$endgroup$
– nmagerko
Dec 23 '11 at 18:20




$begingroup$
It may be commutative if I have two of the same number, but if the sides are 11,6,1, I don't see how they could be commutative. Maybe I am misunderstanding your comment?
$endgroup$
– nmagerko
Dec 23 '11 at 18:20




3




3




$begingroup$
$gcd(a,b,c) = gcd(gcd(a,b),c) = gcd(a,gcd(b,c))=gcd(gcd(a,c),b)$
$endgroup$
– Álvaro Lozano-Robledo
Dec 23 '11 at 18:21




$begingroup$
$gcd(a,b,c) = gcd(gcd(a,b),c) = gcd(a,gcd(b,c))=gcd(gcd(a,c),b)$
$endgroup$
– Álvaro Lozano-Robledo
Dec 23 '11 at 18:21










3 Answers
3






active

oldest

votes


















9












$begingroup$

As others say, one way to do it is using the identity $gcd(a,b,c)=gcd(a,(gcd(b,c))$.
This identity is true since the "gcd" is the maximal element of the intersection of the sets of factors of the inputs. For example, taking $gcd(6,10)$, the set of factors of $6$ is $6, 3, 2, 1$, the set of factors of $10$ is $10, 5, 2, 1$, their intersection is $2, 1$, and the maximal element is $2$. The identity follows since intersections of sets are commutative and associative.



However, it's also possible to extend Stein's algorithm to handle more than two inputs. Wikipedia gives 5 steps to Stein's algorithm, and we can change them to the following to compute the gcd of a set $S$ of numbers:



  1. If anything in $S$ is zero, remove it.

  2. If everything in $S$ is even, divide everything in $S$ by 2, and then multiply the final answer by 2 at the end.

  3. If some numbers in $S$ are even and some are odd, divide all the even numbers by 2.

  4. If every number in $S$ is odd, then choose an arbitrary element of $S$ and call it $k$. Replace every other element, say $n$, with $|n-k|/2$.

  5. Repeat steps 1–4 until there is only one remaining element in $S$. After you remember to multiply in the twos that you got from step 2, that's your gcd!





share|cite|improve this answer











$endgroup$












  • $begingroup$
    I do believe that this algorithm takes the minimal element of the intersection, doesn't it?
    $endgroup$
    – nmagerko
    Dec 23 '11 at 19:26






  • 1




    $begingroup$
    This answer has a mistake in it! In step 4, one should choose the smallest element, and not an arbitrary one. I have tried to edit the answer twice, both tries were rejected.
    $endgroup$
    – AmiguelS
    Jan 23 '18 at 14:54



















0












$begingroup$

Here is J.M. s algorithm implemented as a c++ template class



// Template for GCD
template<typename AType> AType VARGCD(int nargs, ...)

va_list arglist;
va_start(arglist, nargs);

AType *terms = new AType[nargs];
AType result = 0;

// put values into an array
for (int i = 0; i < nargs; i++)

terms[i] = va_arg(arglist, AType);
if (terms[i] < 0)

va_end(arglist);
return (AType)0;


va_end(arglist);

int shift = 0;
int numEven = 0;
int numOdd = 0;
int smallindex = -1;

// Step 1 count number of even and odd
do
n−k / 2.
if (numEven == 0)

for (int i = 0; i < nargs; i++)



while (numEven + numOdd > 1);

// only one remaining element multiply the final answer by 2s at the end.
for (int i = 0; i < nargs; i++)

if (terms[i] == 0)
continue;

return terms[i] << shift;


return 0;
;





share|cite|improve this answer









$endgroup$




















    0












    $begingroup$

    Here's the c++ code to find the gcd (greatest common divisor) of three numbers:



     #include <iostream.h>
    #include<conio.h>
    void main()

    int x,y,z;
    int d,i;
    cout<<"enter three numbers: ";
    cin>>x>>y>>z;
    d=1;
    i=1;

    //condition required

    while(i<=x&&i<=y&&i<=z)

    if(x%i==0&&y%i==0&&z%i==0)

    d=i;
    i++;



    cout<<"GCD: "<<d;
    getch();






    share|cite|improve this answer










    New contributor




    Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$












      Your Answer





      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "69"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      noCode: true, onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f93731%2ffinding-the-gcd-of-three-numbers%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9












      $begingroup$

      As others say, one way to do it is using the identity $gcd(a,b,c)=gcd(a,(gcd(b,c))$.
      This identity is true since the "gcd" is the maximal element of the intersection of the sets of factors of the inputs. For example, taking $gcd(6,10)$, the set of factors of $6$ is $6, 3, 2, 1$, the set of factors of $10$ is $10, 5, 2, 1$, their intersection is $2, 1$, and the maximal element is $2$. The identity follows since intersections of sets are commutative and associative.



      However, it's also possible to extend Stein's algorithm to handle more than two inputs. Wikipedia gives 5 steps to Stein's algorithm, and we can change them to the following to compute the gcd of a set $S$ of numbers:



      1. If anything in $S$ is zero, remove it.

      2. If everything in $S$ is even, divide everything in $S$ by 2, and then multiply the final answer by 2 at the end.

      3. If some numbers in $S$ are even and some are odd, divide all the even numbers by 2.

      4. If every number in $S$ is odd, then choose an arbitrary element of $S$ and call it $k$. Replace every other element, say $n$, with $|n-k|/2$.

      5. Repeat steps 1–4 until there is only one remaining element in $S$. After you remember to multiply in the twos that you got from step 2, that's your gcd!





      share|cite|improve this answer











      $endgroup$












      • $begingroup$
        I do believe that this algorithm takes the minimal element of the intersection, doesn't it?
        $endgroup$
        – nmagerko
        Dec 23 '11 at 19:26






      • 1




        $begingroup$
        This answer has a mistake in it! In step 4, one should choose the smallest element, and not an arbitrary one. I have tried to edit the answer twice, both tries were rejected.
        $endgroup$
        – AmiguelS
        Jan 23 '18 at 14:54
















      9












      $begingroup$

      As others say, one way to do it is using the identity $gcd(a,b,c)=gcd(a,(gcd(b,c))$.
      This identity is true since the "gcd" is the maximal element of the intersection of the sets of factors of the inputs. For example, taking $gcd(6,10)$, the set of factors of $6$ is $6, 3, 2, 1$, the set of factors of $10$ is $10, 5, 2, 1$, their intersection is $2, 1$, and the maximal element is $2$. The identity follows since intersections of sets are commutative and associative.



      However, it's also possible to extend Stein's algorithm to handle more than two inputs. Wikipedia gives 5 steps to Stein's algorithm, and we can change them to the following to compute the gcd of a set $S$ of numbers:



      1. If anything in $S$ is zero, remove it.

      2. If everything in $S$ is even, divide everything in $S$ by 2, and then multiply the final answer by 2 at the end.

      3. If some numbers in $S$ are even and some are odd, divide all the even numbers by 2.

      4. If every number in $S$ is odd, then choose an arbitrary element of $S$ and call it $k$. Replace every other element, say $n$, with $|n-k|/2$.

      5. Repeat steps 1–4 until there is only one remaining element in $S$. After you remember to multiply in the twos that you got from step 2, that's your gcd!





      share|cite|improve this answer











      $endgroup$












      • $begingroup$
        I do believe that this algorithm takes the minimal element of the intersection, doesn't it?
        $endgroup$
        – nmagerko
        Dec 23 '11 at 19:26






      • 1




        $begingroup$
        This answer has a mistake in it! In step 4, one should choose the smallest element, and not an arbitrary one. I have tried to edit the answer twice, both tries were rejected.
        $endgroup$
        – AmiguelS
        Jan 23 '18 at 14:54














      9












      9








      9





      $begingroup$

      As others say, one way to do it is using the identity $gcd(a,b,c)=gcd(a,(gcd(b,c))$.
      This identity is true since the "gcd" is the maximal element of the intersection of the sets of factors of the inputs. For example, taking $gcd(6,10)$, the set of factors of $6$ is $6, 3, 2, 1$, the set of factors of $10$ is $10, 5, 2, 1$, their intersection is $2, 1$, and the maximal element is $2$. The identity follows since intersections of sets are commutative and associative.



      However, it's also possible to extend Stein's algorithm to handle more than two inputs. Wikipedia gives 5 steps to Stein's algorithm, and we can change them to the following to compute the gcd of a set $S$ of numbers:



      1. If anything in $S$ is zero, remove it.

      2. If everything in $S$ is even, divide everything in $S$ by 2, and then multiply the final answer by 2 at the end.

      3. If some numbers in $S$ are even and some are odd, divide all the even numbers by 2.

      4. If every number in $S$ is odd, then choose an arbitrary element of $S$ and call it $k$. Replace every other element, say $n$, with $|n-k|/2$.

      5. Repeat steps 1–4 until there is only one remaining element in $S$. After you remember to multiply in the twos that you got from step 2, that's your gcd!





      share|cite|improve this answer











      $endgroup$



      As others say, one way to do it is using the identity $gcd(a,b,c)=gcd(a,(gcd(b,c))$.
      This identity is true since the "gcd" is the maximal element of the intersection of the sets of factors of the inputs. For example, taking $gcd(6,10)$, the set of factors of $6$ is $6, 3, 2, 1$, the set of factors of $10$ is $10, 5, 2, 1$, their intersection is $2, 1$, and the maximal element is $2$. The identity follows since intersections of sets are commutative and associative.



      However, it's also possible to extend Stein's algorithm to handle more than two inputs. Wikipedia gives 5 steps to Stein's algorithm, and we can change them to the following to compute the gcd of a set $S$ of numbers:



      1. If anything in $S$ is zero, remove it.

      2. If everything in $S$ is even, divide everything in $S$ by 2, and then multiply the final answer by 2 at the end.

      3. If some numbers in $S$ are even and some are odd, divide all the even numbers by 2.

      4. If every number in $S$ is odd, then choose an arbitrary element of $S$ and call it $k$. Replace every other element, say $n$, with $|n-k|/2$.

      5. Repeat steps 1–4 until there is only one remaining element in $S$. After you remember to multiply in the twos that you got from step 2, that's your gcd!






      share|cite|improve this answer














      share|cite|improve this answer



      share|cite|improve this answer








      edited Dec 23 '11 at 18:41









      J. M. is not a mathematician

      61.3k5152290




      61.3k5152290










      answered Dec 23 '11 at 18:37









      LopsyLopsy

      3,7731423




      3,7731423











      • $begingroup$
        I do believe that this algorithm takes the minimal element of the intersection, doesn't it?
        $endgroup$
        – nmagerko
        Dec 23 '11 at 19:26






      • 1




        $begingroup$
        This answer has a mistake in it! In step 4, one should choose the smallest element, and not an arbitrary one. I have tried to edit the answer twice, both tries were rejected.
        $endgroup$
        – AmiguelS
        Jan 23 '18 at 14:54

















      • $begingroup$
        I do believe that this algorithm takes the minimal element of the intersection, doesn't it?
        $endgroup$
        – nmagerko
        Dec 23 '11 at 19:26






      • 1




        $begingroup$
        This answer has a mistake in it! In step 4, one should choose the smallest element, and not an arbitrary one. I have tried to edit the answer twice, both tries were rejected.
        $endgroup$
        – AmiguelS
        Jan 23 '18 at 14:54
















      $begingroup$
      I do believe that this algorithm takes the minimal element of the intersection, doesn't it?
      $endgroup$
      – nmagerko
      Dec 23 '11 at 19:26




      $begingroup$
      I do believe that this algorithm takes the minimal element of the intersection, doesn't it?
      $endgroup$
      – nmagerko
      Dec 23 '11 at 19:26




      1




      1




      $begingroup$
      This answer has a mistake in it! In step 4, one should choose the smallest element, and not an arbitrary one. I have tried to edit the answer twice, both tries were rejected.
      $endgroup$
      – AmiguelS
      Jan 23 '18 at 14:54





      $begingroup$
      This answer has a mistake in it! In step 4, one should choose the smallest element, and not an arbitrary one. I have tried to edit the answer twice, both tries were rejected.
      $endgroup$
      – AmiguelS
      Jan 23 '18 at 14:54












      0












      $begingroup$

      Here is J.M. s algorithm implemented as a c++ template class



      // Template for GCD
      template<typename AType> AType VARGCD(int nargs, ...)

      va_list arglist;
      va_start(arglist, nargs);

      AType *terms = new AType[nargs];
      AType result = 0;

      // put values into an array
      for (int i = 0; i < nargs; i++)

      terms[i] = va_arg(arglist, AType);
      if (terms[i] < 0)

      va_end(arglist);
      return (AType)0;


      va_end(arglist);

      int shift = 0;
      int numEven = 0;
      int numOdd = 0;
      int smallindex = -1;

      // Step 1 count number of even and odd
      do
      n−k / 2.
      if (numEven == 0)

      for (int i = 0; i < nargs; i++)



      while (numEven + numOdd > 1);

      // only one remaining element multiply the final answer by 2s at the end.
      for (int i = 0; i < nargs; i++)

      if (terms[i] == 0)
      continue;

      return terms[i] << shift;


      return 0;
      ;





      share|cite|improve this answer









      $endgroup$

















        0












        $begingroup$

        Here is J.M. s algorithm implemented as a c++ template class



        // Template for GCD
        template<typename AType> AType VARGCD(int nargs, ...)

        va_list arglist;
        va_start(arglist, nargs);

        AType *terms = new AType[nargs];
        AType result = 0;

        // put values into an array
        for (int i = 0; i < nargs; i++)

        terms[i] = va_arg(arglist, AType);
        if (terms[i] < 0)

        va_end(arglist);
        return (AType)0;


        va_end(arglist);

        int shift = 0;
        int numEven = 0;
        int numOdd = 0;
        int smallindex = -1;

        // Step 1 count number of even and odd
        do
        n−k / 2.
        if (numEven == 0)

        for (int i = 0; i < nargs; i++)



        while (numEven + numOdd > 1);

        // only one remaining element multiply the final answer by 2s at the end.
        for (int i = 0; i < nargs; i++)

        if (terms[i] == 0)
        continue;

        return terms[i] << shift;


        return 0;
        ;





        share|cite|improve this answer









        $endgroup$















          0












          0








          0





          $begingroup$

          Here is J.M. s algorithm implemented as a c++ template class



          // Template for GCD
          template<typename AType> AType VARGCD(int nargs, ...)

          va_list arglist;
          va_start(arglist, nargs);

          AType *terms = new AType[nargs];
          AType result = 0;

          // put values into an array
          for (int i = 0; i < nargs; i++)

          terms[i] = va_arg(arglist, AType);
          if (terms[i] < 0)

          va_end(arglist);
          return (AType)0;


          va_end(arglist);

          int shift = 0;
          int numEven = 0;
          int numOdd = 0;
          int smallindex = -1;

          // Step 1 count number of even and odd
          do
          n−k / 2.
          if (numEven == 0)

          for (int i = 0; i < nargs; i++)



          while (numEven + numOdd > 1);

          // only one remaining element multiply the final answer by 2s at the end.
          for (int i = 0; i < nargs; i++)

          if (terms[i] == 0)
          continue;

          return terms[i] << shift;


          return 0;
          ;





          share|cite|improve this answer









          $endgroup$



          Here is J.M. s algorithm implemented as a c++ template class



          // Template for GCD
          template<typename AType> AType VARGCD(int nargs, ...)

          va_list arglist;
          va_start(arglist, nargs);

          AType *terms = new AType[nargs];
          AType result = 0;

          // put values into an array
          for (int i = 0; i < nargs; i++)

          terms[i] = va_arg(arglist, AType);
          if (terms[i] < 0)

          va_end(arglist);
          return (AType)0;


          va_end(arglist);

          int shift = 0;
          int numEven = 0;
          int numOdd = 0;
          int smallindex = -1;

          // Step 1 count number of even and odd
          do
          n−k / 2.
          if (numEven == 0)

          for (int i = 0; i < nargs; i++)



          while (numEven + numOdd > 1);

          // only one remaining element multiply the final answer by 2s at the end.
          for (int i = 0; i < nargs; i++)

          if (terms[i] == 0)
          continue;

          return terms[i] << shift;


          return 0;
          ;






          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Apr 21 '16 at 1:02









          Paul BaxterPaul Baxter

          101




          101





















              0












              $begingroup$

              Here's the c++ code to find the gcd (greatest common divisor) of three numbers:



               #include <iostream.h>
              #include<conio.h>
              void main()

              int x,y,z;
              int d,i;
              cout<<"enter three numbers: ";
              cin>>x>>y>>z;
              d=1;
              i=1;

              //condition required

              while(i<=x&&i<=y&&i<=z)

              if(x%i==0&&y%i==0&&z%i==0)

              d=i;
              i++;



              cout<<"GCD: "<<d;
              getch();






              share|cite|improve this answer










              New contributor




              Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              $endgroup$

















                0












                $begingroup$

                Here's the c++ code to find the gcd (greatest common divisor) of three numbers:



                 #include <iostream.h>
                #include<conio.h>
                void main()

                int x,y,z;
                int d,i;
                cout<<"enter three numbers: ";
                cin>>x>>y>>z;
                d=1;
                i=1;

                //condition required

                while(i<=x&&i<=y&&i<=z)

                if(x%i==0&&y%i==0&&z%i==0)

                d=i;
                i++;



                cout<<"GCD: "<<d;
                getch();






                share|cite|improve this answer










                New contributor




                Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                $endgroup$















                  0












                  0








                  0





                  $begingroup$

                  Here's the c++ code to find the gcd (greatest common divisor) of three numbers:



                   #include <iostream.h>
                  #include<conio.h>
                  void main()

                  int x,y,z;
                  int d,i;
                  cout<<"enter three numbers: ";
                  cin>>x>>y>>z;
                  d=1;
                  i=1;

                  //condition required

                  while(i<=x&&i<=y&&i<=z)

                  if(x%i==0&&y%i==0&&z%i==0)

                  d=i;
                  i++;



                  cout<<"GCD: "<<d;
                  getch();






                  share|cite|improve this answer










                  New contributor




                  Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  $endgroup$



                  Here's the c++ code to find the gcd (greatest common divisor) of three numbers:



                   #include <iostream.h>
                  #include<conio.h>
                  void main()

                  int x,y,z;
                  int d,i;
                  cout<<"enter three numbers: ";
                  cin>>x>>y>>z;
                  d=1;
                  i=1;

                  //condition required

                  while(i<=x&&i<=y&&i<=z)

                  if(x%i==0&&y%i==0&&z%i==0)

                  d=i;
                  i++;



                  cout<<"GCD: "<<d;
                  getch();







                  share|cite|improve this answer










                  New contributor




                  Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|cite|improve this answer



                  share|cite|improve this answer








                  edited 21 hours ago





















                  New contributor




                  Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered yesterday









                  Palomi KuradePalomi Kurade

                  111




                  111




                  New contributor




                  Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Palomi Kurade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Mathematics Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f93731%2ffinding-the-gcd-of-three-numbers%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Solar Wings Breeze Design and development Specifications (Breeze) References Navigation menu1368-485X"Hang glider: Breeze (Solar Wings)"e

                      Kathakali Contents Etymology and nomenclature History Repertoire Songs and musical instruments Traditional plays Styles: Sampradayam Training centers and awards Relationship to other dance forms See also Notes References External links Navigation menueThe Illustrated Encyclopedia of Hinduism: A-MSouth Asian Folklore: An EncyclopediaRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to Play10.1353/atj.2005.0004The Illustrated Encyclopedia of Hinduism: A-MEncyclopedia of HinduismKathakali Dance-drama: Where Gods and Demons Come to PlaySonic Liturgy: Ritual and Music in Hindu Tradition"The Mirror of Gesture"Kathakali Dance-drama: Where Gods and Demons Come to Play"Kathakali"Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceMedieval Indian Literature: An AnthologyThe Oxford Companion to Indian TheatreSouth Asian Folklore: An Encyclopedia : Afghanistan, Bangladesh, India, Nepal, Pakistan, Sri LankaThe Rise of Performance Studies: Rethinking Richard Schechner's Broad SpectrumIndian Theatre: Traditions of PerformanceModern Asian Theatre and Performance 1900-2000Critical Theory and PerformanceBetween Theater and AnthropologyKathakali603847011Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceBetween Theater and AnthropologyBetween Theater and AnthropologyNambeesan Smaraka AwardsArchivedThe Cambridge Guide to TheatreRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeThe Garland Encyclopedia of World Music: South Asia : the Indian subcontinentThe Ethos of Noh: Actors and Their Art10.2307/1145740By Means of Performance: Intercultural Studies of Theatre and Ritual10.1017/s204912550000100xReconceiving the Renaissance: A Critical ReaderPerformance TheoryListening to Theatre: The Aural Dimension of Beijing Opera10.2307/1146013Kathakali: The Art of the Non-WorldlyOn KathakaliKathakali, the dance theatreThe Kathakali Complex: Performance & StructureKathakali Dance-Drama: Where Gods and Demons Come to Play10.1093/obo/9780195399318-0071Drama and Ritual of Early Hinduism"In the Shadow of Hollywood Orientalism: Authentic East Indian Dancing"10.1080/08949460490274013Sanskrit Play Production in Ancient IndiaIndian Music: History and StructureBharata, the Nāṭyaśāstra233639306Table of Contents2238067286469807Dance In Indian Painting10.2307/32047833204783Kathakali Dance-Theatre: A Visual Narrative of Sacred Indian MimeIndian Classical Dance: The Renaissance and BeyondKathakali: an indigenous art-form of Keralaeee

                      Method to test if a number is a perfect power? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Detecting perfect squares faster than by extracting square rooteffective way to get the integer sequence A181392 from oeisA rarely mentioned fact about perfect powersHow many numbers such $n$ are there that $n<100,lfloorsqrtn rfloor mid n$Check perfect squareness by modulo division against multiple basesFor what pair of integers $(a,b)$ is $3^a + 7^b$ a perfect square.Do there exist any positive integers $n$ such that $lfloore^nrfloor$ is a perfect power? What is the probability that one exists?finding perfect power factors of an integerProve that the sequence contains a perfect square for any natural number $m $ in the domain of $f$ .Counting Perfect Powers