TI-BASIC:Math One Liners

From Learn @ Cemetech
Jump to navigationJump to search

This page is dedicated to showcase small snippets of code that may be useful. These small routines are designed to accomplish tasks involving mathematics. Unless specified, output is in Ans.

Primality of Positive Integer – jonbush; lirtosiast

This routine works for 3≤X<106 and returns 0 if X is composite, and 1 if X is prime. If used in an If statement or place where the true value does not matter, you can remove the 0≠.

This code can be modified to be faster if X is already known to be odd.
The following code is faster for large or even X, and works for all 0≤X<3.99*106.
If X≥7 and fPart(.5X

Euler's Phi Function – kg583

This routine calculates the value of Euler's Phi Function for any integer X>3.


Number of Factors – kg583

This routine calculates the number of factors for any integer X>2. A factor is any integer can divide X with no remainder (including 1 and X).