Team 5

Number Theory Explorer

Build an app that explores number theory concepts โ€” prime checking, GCD/LCM computation, Fibonacci generation, modular arithmetic, and prime factorization.

๐ŸŽฏ Learning Goals

  • โ–น Implement Euclidean Algorithm for GCD
  • โ–น Master Prime checking and factorization logic
  • โ–น Understand Modular Arithmetic and sequences
  • โ–น Build multi-panel app navigation with tabs

๐ŸŒŽ Why This Matters

Number theory is the foundation of digital security. Every time you buy something online with a credit card, prime numbers and modular arithmetic are being used to encrypt your transaction. It's the 'purest' math with the most critical impact.

๐Ÿ“–Understanding Number Theory

Theory Masterclass
"

Number Theory is the branch of mathematics that studies properties and relationships of integers. Prime Number: A number greater than 1 that has no divisors other than 1 and itself. Examples: 2, 3, 5, 7, 11, 13... To check if n is prime: try dividing by all numbers from 2 to โˆšn. If none divide evenly, it's prime. GCD (Greatest Common Divisor): The largest number that divides both numbers evenly. Euclidean Algorithm: GCD(a, b) = GCD(b, a mod b), repeat until b = 0. Example: GCD(48, 18) โ†’ GCD(18, 12) โ†’ GCD(12, 6) โ†’ GCD(6, 0) โ†’ Answer: 6 LCM (Least Common Multiple): The smallest number that both numbers divide into. LCM(a, b) = (a ร— b) / GCD(a, b) Fibonacci Sequence: Each number is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34... Modular Arithmetic: The remainder when dividing. a mod n = remainder of a รท n. Example: 17 mod 5 = 2 (because 17 = 3ร—5 + 2)

Mathematical Foundation

fxPrime check: test divisibility from 2 to โˆšn
fxGCD(a,b) = GCD(b, a mod b) โ€” Euclidean Algorithm
fxLCM(a,b) = (a ร— b) / GCD(a,b)
fxFibonacci: F(n) = F(n-1) + F(n-2), F(0)=0, F(1)=1
fxModular: a mod n = a - n ร— floor(a/n)

๐ŸŽจPart A โ€” Designer View (UI Design)

Open MIT App Inventor โ†’ Switch to Designer view. Follow each step below to build the interface.

1

Set up the screen with tabs

Set Screen1 title to "Number Theory Explorer". Add a HorizontalArrangement with 4 tabs as buttons: "Prime", "GCD/LCM", "Fibonacci", "Mod Arithmetic" Each tab shows/hides different panels.

2

Create Prime checker panel

Add a VerticalArrangement named PrimePanel: - TextBox: "Enter a number" (NumbersOnly = true) - Button: "Check Prime" - Button: "Find Factors" - ResultLabel for showing output

3

Create GCD/LCM panel

Add VerticalArrangement named GCDPanel (Visible = false): - HorizontalArrangement: TextBox A, Label "and", TextBox B - Buttons: "Find GCD", "Find LCM", "Find Both" - ResultLabel for output - StepsLabel to show the Euclidean algorithm steps

4

Create Fibonacci panel

Add VerticalArrangement named FibPanel (Visible = false): - TextBox: "How many terms?" (NumbersOnly = true) - Button: "Generate Sequence" - ResultLabel (this will show the full sequence)

5

Create Modular Arithmetic panel

Add VerticalArrangement named ModPanel (Visible = false): - HorizontalArrangement: TextBox A, Label "mod", TextBox N - Button: "Calculate" - ResultLabel

๐ŸงฉPart B โ€” Blocks View (Logic & Calculation)

Switch to Blocks view. Now add the logic that makes your app actually work.

1

Tab switching logic

When PrimeTab.Click โ†’ show PrimePanel, hide other 3 When GCDTab.Click โ†’ show GCDPanel, hide other 3 And so on for Fibonacci and Mod tabs. Change the clicked tab color to green, others to gray.

2

Build Prime checker

When CheckPrimeButton.Click: 1. Set n = number(TextBox.Text) 2. If n < 2 โ†’ "Not Prime" 3. Set isPrime = true 4. Loop i from 2 to sqrt(n): if n mod i = 0 then set isPrime = false, break 5. If isPrime โ†’ show "n is PRIME โœ“" Else โ†’ show "n is NOT prime" For sqrt, use the sqrt block from Math. For mod, use the "modulo of" block.

3

Build Prime Factorization

When FindFactorsButton.Click: 1. Set n = number(TextBox.Text) 2. Create empty list "factors" 3. Set divisor = 2 4. While n > 1: While n mod divisor = 0: Add divisor to factors list n = n / divisor divisor = divisor + 1 5. Display factors list Example: 60 โ†’ [2, 2, 3, 5] โ†’ "2 ร— 2 ร— 3 ร— 5"

4

Build GCD with Euclidean Algorithm

Create procedure "findGCD" with parameters a, b: 1. Initialize steps text = "" 2. While b โ‰  0: steps = steps + "GCD(" + a + ", " + b + ")\n" temp = b b = a mod b a = temp 3. Return a (this is the GCD) 4. Display steps to show the algorithm in action

5

Build LCM

When LCMButton.Click: 1. Calculate GCD first using the findGCD procedure 2. LCM = (a ร— b) / GCD 3. Display: "LCM(a, b) = " + result

6

Build Fibonacci generator

When GenerateButton.Click: 1. Set n = number(TextBox.Text) 2. If n <= 0 โ†’ show error 3. Initialize: a = 0, b = 1, sequence = "0" 4. Loop from 2 to n: next = a + b sequence = sequence + ", " + b a = b b = next 5. Display the full sequence

7

Build Modular arithmetic

When CalculateButton.Click: 1. Set a = number(TextBoxA.Text) 2. Set n = number(TextBoxN.Text) 3. If n = 0 โ†’ show "Cannot divide by zero!" 4. result = a mod n (use "modulo of" block) 5. Display: "a mod n = result" 6. Also show: "a = " + floor(a/n) + " ร— " + n + " + " + result

๐ŸงชTesting Your App

  • โœ“Prime: 97 is prime, 100 is not (factors: 2ร—2ร—5ร—5)
  • โœ“GCD(48, 18) = 6, LCM(48, 18) = 144
  • โœ“First 10 Fibonacci: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
  • โœ“17 mod 5 = 2, 100 mod 7 = 2
  • โœ“Test with large numbers: Is 997 prime? (Yes!)

๐Ÿš€Bonus Challenges

Extra credit โ€” impress your instructor

  • โ˜…Add a 'Generate primes up to N' feature (Sieve of Eratosthenes)
  • โ˜…Show GCD steps visually like a flowchart
  • โ˜…Add GCD of 3 numbers: GCD(a,b,c) = GCD(GCD(a,b), c)
  • โ˜…Calculate Euler's Totient function ฯ†(n)