title: How to find GCD of n with integers smaller than n in R
body: <p>I am trying to find the GCD of the integers &quot;n&quot; with all the integers smaller than &quot;n&quot;. For example, if n=6 ,I am finding the GCD of 6 and 1,2,3,4,5 . Here is my code to find GCD of 2 integers :</p>
  <pre><code>y=function(a,b){
  m=min(a,b)
  while(a%%m&gt;0|b%%m&gt;0){m=m-1}
  return(m)}
  </code></pre>
  <p>I tried using the code below but it only show the first answer.</p>
  <pre><code>y=function(a){
  m=a
  for(i in 1:a){
  while(a%%m&gt;0|i%%m&gt;0){m=m-1}
  return(m)}
  </code></pre>
  <p>How can I modify my code to get the GCDs ? Thankyou in advance !!</p>