Help:=proc(): print(`Gen(S,c) ,IV(k,n)`): end: #The multiplicative semi-group of integers modulo c #generated by the integers in S #For example Gen({2},10); should give {1,2,4,8,6} Gen:=proc(S,c) local S1,S2,s,S3,s2: S1:={1}: S2:=S1 union S mod c: while S1 <>S2 do S3:={seq(seq(s*s2 mod c,s2 in S2),s in S)} union S2: S1:=S2: S2:=S3: od: S1: end: #IV(k,n): the set of vectors of non-negative #integers with k components that add-up to n #For example, IV(1,3) should give {[3]}. IV:=proc(k,n) local S,i,S1: option remember: if k<0 or n<0 then RETURN({}): fi: if k=0 then if n=0 then RETURN({[]}): else RETURN({}): fi: fi: S:={}: #i =last component of the vector for i from 0 to n do S1:=IV(k-1,n-i): S:=S union {seq([op(t),i],t in S1)}: od: S: end: