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 MasterclassNumber 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
šØPart A ā Designer View (UI Design)
Open MIT App Inventor ā Switch to Designer view. Follow each step below to build the interface.
1. Designer Setup
⢠Click **Screen1** in Components. ⢠Set **Title** to "Number Theory Explorer". ⢠Set **AlignHorizontal** to Center. ⢠Set **BackgroundColor** to dark blue.
2. Input Area
⢠Drag a **Label** (User Interface). Set text to "Enter a Number:". ⢠Drag a **TextBox**. Rename it to 'NumInput'. ⢠Set **Width** to 'Fill Parent' and check **NumbersOnly**.
3. Action Buttons
⢠Drag a **HorizontalArrangement** (Layout). ⢠Drag 2 **Buttons** inside. ⢠Rename: 'PrimeBtn' (Text: "Check Prime") and 'FactorBtn' (Text: "Find Factors"). ⢠Style them with bright green text for a "code" feel.
4. Result Display
⢠Drag a **Label** to the bottom. ⢠Rename it to 'ResultLbl'. ⢠Set **FontSize** to 18 and **Text** to "Analysis result will appear here".
š§©Part B ā Blocks View (Logic & Calculation)
Switch to Blocks view. Now add the logic that makes your app actually work.
1. Switch to Blocks
⢠Go to the top right and click the **Blocks** button. ⢠We will now create the math logic for checking primes.
2. The Prime Number Check
⢠Drag 'when PrimeBtn.Click' (Gold). ⢠From **Control** (Orange), drag 'for each number from' block. ⢠Loop from 2 to (NumInput.Text - 1). ⢠From **Math** (Blue), drag subtraction '-' to calculate (NumInput.Text - 1). ⢠Inside the loop, use an 'if...then' (Orange) to check if any number divides perfectly.
3. Using the Modulo block
⢠In the **Math** drawer (Blue), find the 'modulo of' block. ⢠Modulo tells you the remainder. If remainder is 0, it means it divides evenly. ⢠Logic: 'if [modulo of NumInput.Text by number] = 0', then 'set ResultLbl.Text to NOT PRIME'.
4. Getting the Factors
⢠Use **Text** drawer (Bright Pink) 'join' block to create a list. ⢠Every time a number divides evenly (modulo = 0), snap it to the 'join' block. ⢠[set ResultLbl.Text to] [join] [ResultLbl.Text] [", "] [number].
š§Ŗ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)