#OK to post homework #Tianyi Liu, Dec13, Assignment 25 1. 1, 1, 1, 1, 1, 1, 1, 1, 1 1, 1, 1, 1, 1, 1 1, 1, 1, 1, 1 1, 1, 1 1 1 1 [7,4,4,3,3,2,1,1,1] 2. 79811865 3. [[6,5,3,1,1,1,1,1],-1] 8+3(-1)=5<6 [6,4,2,2,2,2,2],0 BZ([[6,5,3,1,1,1,1,1],-1]) [[6, 4, 2, 2, 2, 2, 2], 0] 4. I did not get the error message with pnFast(10000). pnFast(10000) and [seq(PnFast(i),i=1..10000)][10000] take the same amount of time to compute. pnFast(20000); 252114813812529697916619533230470452281328949601811593436850314108034284423801564956623970731689824369192324789351994903016411826230578166735959242113097 5. pnFastMod:=proc(n,m) local s: s:=[seq(PnFast(i),i=1..n)][n]: s mod m: end: 27493510569775696512677516320986352688173429315980054758203125984302147328114964173055050741660736621590157844774296248940493063070200461792764493033510116079342457190155718943509725312466108452006369558934464248716828789832182345009262853831404597021307130674510624419227311238999702284408609370935531629697851569569892196108480158600569421098519 6. InvGlashier:=proc(M) local s,L,i,S: L:=[]: S:=[op(M),0]: s:=1: for i from 1 to nops(S)-1 do if S[i]=S[i+1] then s:=s+1: else L:=[op(L),s]: s:=1: fi: od: for j from 1 to nops(L) do a:=L[j]: count:=0: while a>1 do a:=a mod 2: count:=count+1: od: L1:=[op(L1),] end: finder:=proc(n) local st,count,a,L: st:=n: count:=0: L:=[]: while st>1 do a:=st: while a>1 do a:=a mod 2: count:=count+1: od: if count mod 2=0 then L:=[op(L),2^count]: st:=st-2^count: else L:=[op(L),2^(count-1)]: st:=st-2^(count-1): fi: od: if st=1 then L:=[op(L),1]: fi: L: end: