(* You should be able to copy and paste this text file directly into Mathematica. These notes will be interpreted as commented code. *) (* Note that Mathematica is available free to all Northeastern students. For more information, please go here: https://service.northeastern.edu/tech?id=kb_article&sys_id=14049b9347990d10b9dd586c346d431d *) (* You can also access the cloud version of Mathematica directly through the Math 3527 Canvas page. Click "Mathematica" on the left sidebar. *) (* ********* Here are the numbers from the problems ******** *) problem1N := 1359692821 problem1a := 414892055 problem1b := 823845737 problem2N := 1085444233 problem2a := 277891194 problem2c := 878460400 problem3N := 3189493285075919531948989803351695476743251123 problem3e := 65537 problem3c := 2959053278713961285937339429986943039861423195 problem4N := 488419441734583556321985415212612123740359939381088965700730231638206554681394177 problem4s2 := 364578471930898294925524638136447727960007605573204140075455802888652544203808336 problem4u12:= 419987940537002829673554859623446087647247049378701209589622515994832674140645748 problem4u22:= 270893145623915322344834242328268768371424519375297223857305039560421032101793802 problem4u32:= 001204179001250513038323769136188667129468312291612708387897338022926559640599640 problem4u42:= 295360259330799676568102779994887111797263481168605647699269117672956353312755331 problem4u52:= 076085193608240660534079611034851894964763400993326547711532912132418924025617595 problem4v1 := 368836285783665928691160226566669484193845816214794656578305054442600293140251910 problem4v2 := 061162076090849776429311938634702834494489117638106960807555056103441302535633013 problem4v3 := 187951496312843107888323763535831510839656637929611417672687000373287147716755997 problem4v4 := 174908257541270590422202403049766598633440061550219493518183063157021792026188460 problem4v5 := 018020803226473941195493125743250937332254656547401271200890367477647082876441426 problem5NB := 49703407978872135768369150951737194603841663052986938247511157126794635921277619 problem5NC := 48394585785126752760098222942433754518772506574482068079987934034981215730453293 problem5ND := 37048466581842421945081537172098726013070671280095643279361407260434395186752267 problem5cB := 05905364385466286295586251025237668938472190855132358966957728964323606634400251 problem5cC := 21138220486961146446206617482811850561629767638994082201111978852676605086081807 problem5cD := 27157125477984404879431019780288127319483825029543848767280738662683083014939218 problem8bN := 45737 * 54377 problem8bd := 1657960491 (* ******* Here is code for decoding a number string ******* *) NumbersToString[list_] := StringJoin[FromLetterNumber[list + 1]] NumberStringList[n_] := PadLeft[IntegerDigits[n], 2*Ceiling[Length[IntegerDigits[n]]/2]] NumberListConvert[list_] := Table[FromDigits[list[[2 i - 1 ;; 2 i]]], {i, 1, Length[list]/2}] NumberToString2[n_] := NumbersToString[NumberListConvert[NumberStringList[n]]] (*This will convert an integer into its corresponding letter string,where a=00,b=01,...,z=25*) NumberToString2[0704111114] (*This should return the string "hello"*) (* ********* Here are some useful commands for powers mod m ******** *) Mod[100,6] (* This will compute 100 modulo 6, yielding 2 *) PrimeQ[201] (* This will test whether 201 is prime, which it is not *) FactorInteger[143] (* This will factor the integer 143, which is 11 times 13 *) (* Mathematica's factorization algorithm knows how to do trial division, Pollard p-1, Pollard rho, quadratic sieving, and elliptic curve factorization, and is typically fairly fast on numbers with less than 50 digits *) largeval := 2^128 + 1 Timing[PrimeQ[largeval]] Timing[FactorInteger[largeval]] (* Note that you can also apply functions directly to named variables. The above allows you to see how much faster primality testing is compared to factorization *) PowerMod[2, 10, 99] (* This will compute 2^10 modulo 99. PowerMod is efficient and will use successive squaring *) (* Mod will often also recognize if you give it a power and internally call PowerMod, but it is better to use PowerMod directly *) PowerMod[2, -1, 99] (* This will compute 2^(-1) modulo 99, which is to say, the multiplicative inverse of 2 modulo 99. *) EulerPhi[40] (* This will compute phi(40). *) ChineseRemainder[{1,2,3},{4,5,9}] (* This will compute the smallest positive integer solution to x = 1 mod 4, x = 2 mod 5, x = 3 mod 9 *) CubeRoot[64] (* This will compute the cube root of 64. You can also obtain this as 64^(1/3), but fractional powers can sometimes behave unexpectedly because of how Mathematica handles complex numbers. *) (* ********* Here are some useful other commands ******** *) GCD[180, 250] (* This computes the GCD of 180 and 250 *) ExtendedGCD[180, 250] (* This performs the extended Euclidean algorithm, and computes the GCD = 10 along with integers {x,y} such that 180x + 250y = 10 *) PrimitiveRoot[25] (* This calculates the smallest primitive root modulo 25 *) MultiplicativeOrder[7, 25] (* This calculates the order of 7 modulo 25 *) Solve[x^3 == 1, x, Modulus -> 49] (* This calculates all of the numbers x satisfying the equation x^3 = 1 modulo 49 *) Reduce[x^3 == 1, Modulus -> 49] (* This simplifies the equation x^3 = 1 modulo 49, which here will give a list of all the solutions *)