🏗️ ΘρϵηΠατπ🚧 (under construction)

Prime
A number p2 is said to be prime if it's only divisors are 1 and p symbolically that is dN1,(dp)d{1,p}
Set of Primes
We denote the set of primes as P
If a Prime Divides Another they are Equal
Suppose that p,qP, then pqp=q
Primes of the Form 4k Plus Something
Suppose that pP3 then there exists some kN0 such that p=4k+1 or p=4k+3
Increasing Prime Function
We let the function pi:N1P be an increasing function such that p1=2 and there are no primes between pi and pi+1.

This function looks like 2,3,5,7,11,13,17,

Composite
We say that nZ where |n|2 is composite if there exists an x{2,,n1} such that xn

The composites union the primes is Z{1,0,1}

Composite iff Not Prime
Let aN1 then a is composite iff a is not prime
A Prime is Relatively Prime to Anything Else That is Not a Multiple of It
Suppose that p is prime and nZ then pn iff gcd(p,n)=1
A Prime Divisor of a Product Divides at Least One
If p,a,bZ and we know p is prime and pab then pa or pb.
Every Number is Divisible by a Prime
For any nN2 there is a prime p such that pn
Every Number is a Product of Primes
For every nN2 n:=p1·p2··pk for some kN1
There are Infinitely Many Primes
As per title.
There is a Prime Between n and n Factorial
For any nN3 there is a prime number p such that n<p<n!
n Minus 1 Factorial is Divisible by n
Let nN4, show that if n is not a prime then we have (n1)!{2(modn) if n=4,0(modn) if n5
There are Gaps of Arbitrary Size between Consecutive Primes
Suppose that (p1,p2,p2,) is an increasing sequence of all the primes, then for every mN1 there exists an NN1 such that pN+1pNm
Fundamental Theorem of Algebra
For every nN2 can be written uniquely as n=iN1piαi αiN1 where all but finitely many αi=0
Prime Factors
Let nN2 and consider its prime factorization n=iN1piαi αiN1 where all but finitely many αi=0 then we define pf(n)={pi:αi1}
Prime Power Sequence
Given any nN1 and its prime factorization iN1piai then we define pps(n):=(a1,a2,a3,) Note that pps:N2{(xn):N1N0}

Note that since each number has a unique factorization then pps is a bijection, and so pps1 exists.

Products as the Addition of Power Sequences
Suppose that a,bN2 then pps(ab)=pps(a)+pps(b)
Max of the Prime Power Sequence is 0 iff They share no Prime Factors
Let a,bN2 then pf(a)pf(b)=max(pps(a),pps(b))=0
Relatively Prime In terms of Prime Factorization
The following are equivalent
  1. gcd(a,b)=1
  2. max(pps(a),pps(b))=0
  3. pf(a)pf(b)=
Coprime and 5
Suppose that a,bZ are coprime, then find all possible values of gcd(a+b,5ab)
Subsequence of the sum of Two Disjoint Power Sequences Is Still a Disjoint Sum
Suppose that max(pps(a),pps(b))=0 and that (xn)pps(a)+pps(b) then (xn)=(an)+(bn) where (an)pps(a) and (bn)pps(b) and max((an),(bn))=0
A Number Divides a Coprime Product iff It is the product of Individual Divisors
Suppose that gcd(a,b)=1 then cab if and only if c=dadb where da,db are divisors of a,b respectively
Euclid
For any a,b,pN1 then if p is prime, we have pab((pa)(pb))
If a Prime Divides a Product it Divides at Least One of the Factors
Suppose that a1,anN1 and pi=1nai then there exists a k[1,,n] such that pak
Prime Divisors of a Factorial are Bounded by the Argument
For every pP and nN2 such that pn! then pn
A Divisor of a Product of Primes is a Product of Primes with Smaller Powers
Suppose that dm
GCD and LCM as Prime Powers
Suppose that P={p1,pk} is a collection of primes such that a=piPpiαi and b=piPpiβi where αi,βiN0, then gcd(a,b)=piPpimin(αi,βi) and lcm(a,b)=piPpimax(αi,βi)
Perfect Square iff Every Power in the Prime Factorization is Even
Let nN1 then n is a perfect square if and only if n=iN1pi2αi
Division and Prime Power Equivalence
Suppose that a,dN2 then dapps(d)pps(a)
Every Composite Three Digit Number must have a Prime Factor Less than or Equal to 31
As per title.
Lower Bound on Primes in Factorization Limits the Number of Prime Factors
Let nN2 and suppose that pn for all primes pn3, what can we conclude about the prime factorizatio of n ?
Goldbach Equivalence
Show that every even integer >2 is the sum of two primes if and only if every integer >5 is the sum of three primes
p Minus one Factorial is Congruent to Minus one Mod p
Suppose that pN2 is prime, then (p1)!1(modp)

The above is usually referred to "Wilsons Theorem".

p Minus two Factorial is Congruent to One Mod p
Suppose that pN2 is prime, then (p2)!1(modp)

This allows us to conclude things like: 15!1(mod17).

Factorial Fun
Find the remainder when 4(29!)+5! is divided by 31
1 2 3 n go
Show that for any nN2 then n2(n3)!+1 iff n is prime
Generalized Wilson's Theorem
Suppose that pP and that a[1,,p] then we have (a1)!(pa)!(1)a
Wilson Folded in Half
Suppose that pN3 is prime, then [(p12)!]2(1)p+12(modp)
Fermats Helper
Suppose pN2 is prime, and aZ so that pa then ap11(modp)
Fermats Helper Mod Exponent
Suppose that pN2 is prime, and a,bZ such that pa then abab % (p1)(modp)
Fermats Little
For any pN2 which is prime, then for any aZ we have apa(modp)
Remainder of Power Plus One
Find the remainder of 11104+1 modulo 17
2's and 5's
Show that 22225555+55552222 is divisible by 7
Prime Power Sum
Suppose that pP3 then compute (1p+2p+3p++(p1)p) % p
If a Doesn't Divide p Then Fermats Little Theorem and Fermats Little Helper are Equivalent
Suppose that pN2 is prime and aZ such that pa then ap11apa(modp)
Almost Prime
Show that for any aZ we have a9a(mod30)
Carmichael
We say that nN1 is carmichael if ana(modn) for every aZ, and n is not a prime.
561 is Carmichael
As per title.
Korselt's Criterion
nN1 is Carmichael if and only if n is squarefree and for every prime p such that pnp1n1.
1729 is Carmichael
As per title.
Fermats Compositeness Test
Suppose n,aZ such that gcd(a,n)=1 then if an11(modn) then n is composite
Fermat Witness
If n,a passes the compositeness test, then a is said to be a Fermat Witness for n
Pseudoprime to base a
Suppose that n,aZ and that an11(modn) and n is not prime, then n is called a pseudoprime to base a.

Most of the time when you find that an11(modn), then n is prime, that's why the ones that aren't are called pseudoprimes.

341 is a Pseudoprime to base 2
As per title.
Fermat Primality Test
Let nN2, and define the following function f(X):
  1. if X= return T
  2. let aX
  3. if an11(modn) return F
  4. return f(X{a})
Let G={x[1,,n2]:gcd(x,n)=1}. If f(G)=F then n is composite, otherwise we say that n is a probable prime
Every Carmichael Number is a Probable Prime
Suppose nN1 is Carmichael, then using the Fermat Primality Test, it is a probable prime.
At Least Half of the Tested Elements will be Witnesses to a Composite Non-Carmichael Number
Suppose that nN1 is composite and not Carmichael and let G={g[1,,n1]:gcd(g,n)=1} and W={wG:wn11(modn)}, then |W||G|2
Every Odd Number is a Difference of Squares
For any nN1 that is odd there exists x,yN1 such that n=x2y2
The Sum is less than or Equal to the Product
Suppose that a,bN2 then a+ba·b if a<b or b<a then a+b<a·b
Fermats Factorization
Suppose that nN2 is odd, then n is composite iff there exists x,yN1 such that n=x2y2 where xn+12
            
import math

def fermat_factor(n):
    assert n % 2 != 0, "Fermat's factorization method works only for odd integers."

    print(f"Starting Fermat's factorization for n = {n}")

    # Calculate the ceiling of the square root of n
    x = math.ceil(math.sqrt(n))
    print(f"Initial x (ceiling of the square root of n): {x}")

    if x * x == n:
        print(f"{n} is a perfect square. Factors are {x} and {x}.")
        return x, x

    y2 = x * x - n
    print(f"Initial y^2 = {x}^2 - {n} = {y2}")

    # Loop will always terminate because (x, y) = ((n + 1) / 2, (n - 1) / 2) is a valid solution
    while not last_two_digits_possible_square(y2) or not is_perfect_square(y2):
        print(f"y^2 = {y2} is not a perfect square. Incrementing y^2 and then x.")

        # Update y^2 incrementally
        y2 += 2 * x + 1  # Efficiently calculate the next y2 using (x+1)^2 = x^2 + 2x + 1
        x += 1  # Increment x after updating y^2

        print(f"New x = {x}, new y^2 = {x}^2 - {n} = {y2}")

    y = int(math.isqrt(y2))
    print(f"Found perfect square y^2 = {y2}. y = sqrt({y2}) = {y}")
    print(f"Factors are (x - y) = {x - y} and (x + y) = {x + y}")

    return (x - y, x + y)

def last_two_digits_possible_square(n):
    # Set of possible last two digits of a perfect square
    possible_last_two_digits = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81,
                                20, 21, 24, 25, 29, 41, 44, 45, 61, 69, 84}
    return (n % 100) in possible_last_two_digits

def is_perfect_square(n):
    # Check if the number is a perfect square
    root = int(math.isqrt(n))
    return root * root == n

# Example usage:
n = 5959
factors = fermat_factor(n)
print(f"The factors of {n} are {factors}")