Re: Help with "If" statement within "Table"

*To*: mathgroup at smc.vnet.net*Subject*: [mg90534] Re: [mg90500] Help with "If" statement within "Table"*From*: Sseziwa Mukasa <mukasa at jeol.com>*Date*: Sat, 12 Jul 2008 05:31:24 -0400 (EDT)*References*: <200807110602.CAA03738@smc.vnet.net>

On Jul 11, 2008, at 2:02 AM, Diana wrote: > Folks, > > I am trying to write a small program to count the number of divisors > of a number which have at least one coprime neighbor, and secondly the > number of divisors which have two coprime neighbors, (one on each > side). > > For example, the divisors of 60 are {1, 2, 3, 4, 5, 6, 10, 12, 15, 20, > 30, 60}. 6 of the divisors have at least one coprime neighbor, and 5 > of the divisors have two coprime neighbors. > > In doing this, I have written the following statement. "n" is the > number for which I am calculating divisors, and "A136164" is my first > list, the of number of divisors in the "at least one neighbor" case. > For some reason, A136164 is not updating when the "If" statement is > executed within the "Table" statement. Can someone help me? Thanks, > Diana M. > > Table[If[CoprimeQ[Divisors[n][[j]], Divisors[n][[j - 1]]] || > CoprimeQ[Divisors[n][[j]], Divisors[n][[j + 1]]], > A136164[[n]] = A136164[[n]] + 1,], {j, 3, > Length[Divisors[n]] - 2}]; > Did you initialize the list A136164 to be a list at least n long first? (Debug) In[14]:= A136164=ConstantArray[0,60] With[{n=60}, Table[If[CoprimeQ[Divisors[n][[j]],Divisors[n][[j-1]]]||CoprimeQ [Divisors[n][[j]],Divisors[n][[j+1]]],A136164[[n]]=A136164[[n]]+1,], {j,3,Length[Divisors[n]]-2}]]; A136164 (Debug) Out[14]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} (Debug) Out[16]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4} There seem to be other problems with your algorithm though, it only finds 4 coprime neighbors. Regards, Ssezi

**References**:**Help with "If" statement within "Table"***From:*Diana <diana.mecum@gmail.com>