ΘρϵηΠατπ

Prime
A number p2 is said to be prime if it's only divisors are 1 and p symbolically that is d1,(d|p)d{1,p}
Set of Primes
We denote the set of primes as
If a Prime Divides Another they are Equal
Suppose that p,q, then p|qp=q
Since p|q then we know that p=1 or p=q the former is impossible since 2 therefore p=q as needed.
Primes of the Form 4k Plus Something
Suppose that p3 then there exists some k0 such that p=4k+1 or p=4k+3
By the quotient remainder theorem we have that p=4q+r where q and r[0,,q1], when p=3 the only possibility is that q=0 and r=3, on the other hand for any p5 we have that q1, now if q=0 or r=2 then the prime is divisible by 2 and which makes p not prime, which is a contradiction, therefore r{1,3}.
Increasing Prime Function
We let the function pi:1 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 n where |n|2 is composite if there exists an x{2,,n1} such that x|n

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

Composite iff Not Prime
Let a1 then a is composite iff a is not prime
We know that it's always true that a|a and 1|a therefore if a is not prime iff it has some other divisor other than 1 or a iff a is composite
A Prime is Relatively Prime to Anything Else That is Not a Multiple of It
Suppose that p is prime and n then pn iff gcd(p,n)=1

Since p is prime, then its only divisors are 1 and itself. We assume that p does not divide n therefore that's the same as saying that n is not a multiple of p. Now if we consider gcd(p,n) then its subset of the divisors of p so the gcd could only p or 1, if it were p that would imply that p|n but that's a contradiction, therefore the gcd is 1.

Suppose that gcd(p,n)=1 and for the sake of contradiction that p|n that means there is a k such that n=kp in that case we have gcd(p,n)=gcd(p,kp) therefore gcd(p,kp)p which is a contradiction because any prime is greater than one.

A Prime Divisor of a Product Divides at Least One
If p,a,b and we know p is prime and p|ab then p|a or p|b.
If p were to divide a, the proof is over so we assume that it does not. therefore gcd(p,a)=1 and then 1=as+pt, then b=(ab)s+ptb=(kp)s+ptb, so then p divides the right hand side, therefore p|b, as needed.
Every Number is Divisible by a Prime
For any n2 there is a prime p such that p|n

To show existance we will use the well ordering principle so consider the set S:={c2:c|n} observe that nS so therefore S and therefore by the well ordering principle it has a least element pS therefore by the definition of S we know that p|n, lets show that p is prime.

Let d1,d|p if d=1, then d{1,p} so all is well, on the other hand if d>1 so that d2 then since we already knew that p|n and that division is transitive then we know that d|n which means that dS, since p is the minimal element of S then pd at the same time since d|p then we know that dp, thus since is anti-symmetric, then d=p.

Thus p is prime, and p|n as needed.

Every Number is a Product of Primes
For every n2 n:=p1p2pk for some k1

We prove the statement true via strong induction, for the base case of n=2 we see that p1=2 works, namely that 2=2.

Now suppose for some j2 the statement we'd like to prove holds for {2,,j} we'll prove that the statement holds true for j+1, so consider j+1, if it is prime, then we are done, as we can take it as the singleton product, elsewise it is not prime, and therefore it is composite so we get a,b2 such that ab=j+1 by our induction hypothesis we know that the statement holds true for a,b and thus we get a=p1pn and b=q1qm for some m,n1, thus j+1=p1pnq1qm so that j+1 is the product of m+n primes as needed.

There are Infinitely Many Primes
As per title.
Suppose that there were finitely many primes, and we listed all of them here: p1,pk for k1 and consider M:=p1pk+1 For every i[1,k] we have that M % pi=1 therefore piP, at the same time M must be divisible by some prime p but clearly ppi for any i[1,k] or else M % pi=0 which would be a contradiction, since it's not equal to any of the primes we listed, this is a contradiction because we know that it contained all primes, therefore our assumption is incorrect and there must be infinitely many primes.
There is a Prime Between n and n Factorial
For any n3 there is a prime number p such that n<p<n!
Let N={p:pn} since n3 then at least 2,3N so it is non-empty. Since n!6 then we know that n!12 and therefore there is a prime number which divides it, say it is q, for any pN we know that n!11(modp) therefore qN thus q>n, since q|n!1 then qn!1<n! so that n<q<n!
n Minus 1 Factorial is Divisible by n
Let n4, show that if n is not a prime then we have (n1)!{2(modn)amp; if n=4,0(modn)amp; if n5

In the case that n=4 then we know that (n1)!=6 which has remainder 2 upon division by 4 as needed.

On the other hand, whenever we have n5 then since n is not prime, then it is composite and therefore there exists a,b[2,,n1] such that n=ab. If ab then (n1)!=(n1)ab21 therefore n=ab|(n1)! so that (n1)!0(modn).

On the other hand, supposing that a=b then we see that n=a2 since a2 then we know that a22a. Actually we know more, since n5 then a>2 so we can say that a2>2a so that n>2a so that a,2a both appear in the factorials product so that a2|(n1)! as needed.

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 m1 there exists an N1 such that pN+1pNm
Let m1, consider the following numbers (m+1)!+2,(m+1)!+3,,(m+1)!+(m+1) since there are (m+1)2+1=m numbers here, and for each element of the form (m+1)!+i we know that i|(m+1)!+i since i2 this makes it composite, and thus not prime, thus take N as the greatest index such that pN<(m+1)!+2 thus the gap between pN and pN+1 must be at least m as needed.
Fundamental Theorem of Algebra
For every n2 can be written uniquely as n=i1piαi αi1 where all but finitely many αi=0
Prime Factors
Let n2 and consider its prime factorization n=i1piαi αi1 where all but finitely many αi=0 then we define pf(n)={pi:αi1}
Prime Power Sequence
Given any n1 and its prime factorization i1piai then we define pps(n):=(a1,a2,a3,) Note that pps:2{(xn):10}

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,b2 then pps(ab)=pps(a)+pps(b)
Max of the Prime Power Sequence is 0 iff They share no Prime Factors
Let a,b2 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,b are coprime, then find all possible values of gcd(a+b,5ab)

Let's consider a common divisor d of a+b and 5ab recall that there exists a p such that p|d therefore by transitivity we have p|a+b and p|5ab in the latter case, we see that either p|5 or p|a or p|b.

If p|a then we know that p|b but then gcd(a,b)1 which would be a contradiction, therefore pa, but symmetrically pb therefore we must have that p|5 therefore p=5

The above says that given any prime divisor of d then it turns out that prime divisor must be 5 therefore d=5k for some k1. Suppose that k2, if that's true then we have 5k|5ab and 5k|a+b from the former so we have 5k1|ab therefore 5k1|a or 5k1|b, without loss of generality if we assume that 5k1|a then in conjunction with 5k|a+b we have j5k=a+b=5k1l+b therefore b=5k1(j5l) so that 5k1|b therefore gcd(a,b)5k1 which is a contradiction, therefore it must be that k=1.

Therefore the only possible values of d is 1 or 5 therefore the only possible values of gcd(a+b,5ab) is 1 or 5

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 c|ab if and only if c=dadb where da,db are divisors of a,b respectively

Suppose that c|ab therefore pps(c)pps(ab)=pps(a)+pps(b) and therefore pps(c)=(an)+(bn) where (an)pps(a) and (bn)pps(b) where max((an),(bn))=0 (by the corollary). Therefore c=pps1(an)pps1(bn) but we know that pps1(an)|a and pps1(bn)|b as needed.

Suppose that c=dadb, since they are divisors we know that there exist ka,kb such that a=kada and b=kbdb so then ab=kakbdadb=kakbc therefore c|ab as needed.

Euclid
For any a,b,p1 then if p is prime, we have p|ab((p|a)(p|b))
If a Prime Divides a Product it Divides at Least One of the Factors
Suppose that a1,an1 and p|i=1nai then there exists a k[1,,n] such that p|ak
Prime Divisors of a Factorial are Bounded by the Argument
For every p and n2 such that p|n! then pn
Since p|1n then there exists some k[1,,n] such that p|k therefore pkn so that 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,βi0, 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 n1 then n is a perfect square if and only if n=i1pi2αi

Suppose that n is a perfect square therefore n=m2 for some m but we know that m=i1piβi therefore n=(i1piβi)2=i1pi2β2

We have that n=i1pi2αi=(i1piαi)2 therefore n is a perfect square.

Division and Prime Power Equivalence
Suppose that a,d2 then d|apps(d)pps(a)
Every Composite Three Digit Number must have a Prime Factor Less than or Equal to 31
As per title.
Assume that for the sake of contradiction the statement was not true, therefore there is a three digit number such that all of its prime factors are greater than 31, the next prime is 37 and so the smallest three digit number hvaing all prime factors greater than 31 would be 372=1369 which is a four digit number, thus our assumption was false, so that every three digit number must have a prime factor less than or equal to 31.
Lower Bound on Primes in Factorization Limits the Number of Prime Factors
Let n2 and suppose that pn for all primes pn3, what can we conclude about the prime factorizatio of n ?
Suppose that n=i=1kpiαi, we can see that pi|n and therefore by the contrapositive of our assumption we have that pin3 therefore k2 for if k3 then namp;=i=1kpiαiamp;i=1kpiamp;i=13piamp;>n3n3n3amp;=n so we've shown that n>n which is a contradiction so indeed k2, therefore we conclude that the prime factorization of n has at most two different primes in it.
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

Suppose the former, let n1 such that n>5 if n is even, then so is n2 and we see n2>2 and so n2=p1+p2n=p1+p2+2, otherwise use 3.

Suppose the latter and let n>2 be even, in other words n4>3 therefore n+2 is an even number and we know that n+2>5 therefore n+2=p1+p2+p3, since n+2 is even then so is p1+p2+p3 but the sum of three numbers is only even when exactly one is even or all are even, therefore at least one of them is even, but there is only one even prime number, and therefore without loss of generality assume that p1=2 so we have n+2=2+p2+p3 and therefore n=p2+p3 as needed.

p Minus one Factorial is Congruent to Minus one Mod p
Suppose that p2 is prime, then (p1)!1(modp)

Recall that S={0,,p1} is a complete set of residues mod p, and also for any sS since gcd(s,p)=1 then the collection T={0,s,s(p1)} is a complete system of residues mod p. Since it is then there is exactly one element jT such that j1(modp) specifically j=st where tS so we can say that st1(modp).

In the previous paragraph we've shown the existance of a function f:SS such that xf(x)1(modp). We're going to prove this function is injective, that is we will prove that if x,yS then f(x)=f(y)x=y. Suppose that f(x)=f(y) therfore f(x)f(y)(modp) moreover by the definition of f we know that xf(x)1yf(y)(modp) therefore we have xf(x)yf(y)yf(x)(modp) thus since f(x)S we know that gcd(f(x),p)=1 therefore xy(modp1) so that x=y as needed. As a side note since the size of the domain is the same as the size of the range, then we know that f is a bijection.

For a moment let's consider the case when f(x)=x if that were true we have xf(x)x21(modp) therefore x±1(modp) if x1(modp) this means that p|x1, if x10 then we know that p|x1|, since xS then x1{1,p2} so that |x1|p2 but then we deduced that pp2 which is a contradiction so that we must have x1=0 so that x=1. On the other hand if we know that x1(modp) then we see that p|x+1 since x+1{1,,p} then the only possibility is that x+1=p which is that x=p1.

The result of the above paragraph is that if f(x)=x then the only possibility is that x=1 or that x=p1, so x{2,,p2}f(x)x and f(x){2,,p2}, and this function is a bijection, remaining a bijection on the restriction of the domain and range to {2,,p2}.

For a moment note that if p=2 this whole question is trivial because (21)!1(mod2), therefore we can assume that p3 also this implies that p is odd, therefore when we consider the collection K={2,,p2} then since |K|=p22+1=p3 then the size of K is even since p is odd. Let k1K then f(k1)k, Let K1=K{k1,f(k1)}, since f is a bijection, then by repeating this process l=|K|2 times then Kl= which is to say that {{ki,f(ki)}:i[1,,l]} is a partition of K, thus 2(p2)=i=1lkif(ki) But we see i=1lkif(ki)i=1l11(modp) and therefore 2(p2)1(modp) therefore (p1)!2(p2)(p1)1(p1)1(modp) as needed.

The above is usually referred to "Wilsons Theorem".

p Minus two Factorial is Congruent to One Mod p
Suppose that p2 is prime, then (p2)!1(modp)
Recall that (p1)!1(modp) but at the same time we know that (p1)!(p1)(p2)!1(p2)! therefore multiplying both sides by 1 we obtain that (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
We know that 29!1(mod31) and that 5!=120 therefore 4(29!)+5!1244(31)0(mod31)
1 2 3 n go
Show that for any n2 then n|2(n3)!+1 iff n is prime
Suppose that n is prime, therefore (n2)!1(modn) we also know that n22(modn) therefore we know that (n3)!(2)1(modn)2(n3)!1(modn) thus 2(n3)!+10(modn) as needed.

For the other direction assume that n|2(n3)!+1 therefore we know that 2(n3)!1(modn) by multiplying both sides by -1, re-writing the factorial and then multiplying by -1 again, we obtain that (n1)!1(modn) therefore by wilsons theorem we know that n is prime.

Generalized Wilson's Theorem
Suppose that p and that a[1,,p] then we have (a1)!(pa)!(1)a
We know that the base case holds. Therefore we move directly to the induction step, where we assume that the statement holds true for k1, and we have to prove that (k)!(pk1)!(1)k+1 We have that (1)kamp;(k1)!(pk)!(k1)!(pk)(pk1)!(k1)!(k)(pk1)!(1)k!(pk1)! thus by multiplying both sides by 1 we obtain that k!(pk1)(1)k+1 as needed.
Wilson Folded in Half
Suppose that p3 is prime, then [(p12)!]2(1)p+12(modp)
Observe that p12,p+121 since p is odd. Since 1<p then we know 2<p+1<2p so that 1<p+12<p, similarly since 3p then 2p1<p so that 1p12<p2<p, moreover p12+1=p+12 therefore we have: (p1)!=12(p12)(p+12)(p1)

focusing on the terms that come after p12 in the above product we see p+12amp;p12(modp)amp;p2amp;2(modp)p1amp;1(modp) that first congruence comes from the fact that p+12=pp12, and notice that they are congruent to the negative versions of the terms in the first half of the factorial, and so we can "fold" it in half to get (p1)!1(1)2(2)(p12)(p12)(modp) Since there are exactly p12 negative terms we can factor a 1 out from all of them, leaving square of the consecutive numbers so that (p1)!(1)p12(12p12)2(modp) by wilsons theorem we know that (p1)!1(modp) therefore we have 1(1)p12[(p12)!]2(modp) since p is odd, then p1 is even, therefore (1)p1=1, therefore 1(1)p12amp;(1)p12(1)p12[(p12)!]2(modp)(1)p12+22amp;(1)p1[(p12)!]2(modp)(1)p+12amp;[(p12)!]2(modp) as needed.

Fermats Helper
Suppose p2 is prime, and a so that pa then ap11(modp)
Recall that R={0,,p1} is a complete system or resides mod p, and since gcd(p,a)=1 then so is A={0,,a(p1)} therefore xA{0}x(p1)!(modp) But we also know that xA{0}x=ap1(p1)! so we conclude that (p1)!ap1(p1)!(modp) But then ap11(modp)
Fermats Helper Mod Exponent
Suppose that p2 is prime, and a,b such that pa then abab % (p1)(modp)
By the quotient remainder theorem we know that b=q(p1)+r where r=b % (p1) therefore abamp;aq(p1)+ramp;aq(p1)aramp;(ap1)qaramp;1qaramp;arab % (p1)(modp) where in the 3rd last line we used fermats helper.
Fermats Little
For any p2 which is prime, then for any a we have apa(modp)

Suppose p|a then the statement holds true as 0p0(modp). On the other hand if pa then ap11(modp) so by multiplying by a we have apa(modp)

Remainder of Power Plus One
Find the remainder of 11104+1 modulo 17
Observe that by fermats helper since 1711 we have that 11161(mod17) since 104=166+8 then we see that 11104(1116)6(11)8118(mod17) since 112=121=177+2 then 118(112)4161(mod17) therefore 11104+10(mod17)
2's and 5's
Show that 22225555+55552222 is divisible by 7

Note that in general AB010101=ABABAB, therfore note that 5555=10155 and that 2222=10122.

We use this to simplify each base mod 7, we have that 5555amp;10155amp;(714+3)(77+6)amp;3(mod7)

also that 2222amp;10122amp;3(73+1)amp;3 therefore we know that 22225555+55552222(3)5555+32222(mod7) We will now look at 2222 % 6 since we know that 2220 % 6=0 then 2222 % 6=2, we will now look at 5555 % 6 since we know that that 5550 % 6=0 then 5555 % 6=5 therefore (3)5555+32222(3)2+315+20(mod7)

Prime Power Sum
Suppose that p3 then compute (1p+2p+3p++(p1)p) % p
Since for each x[1,,p1] we know that by fermats little theorem that xpx(modp) thus we have that i=1p1ipi=1p1i(p1)p2(modp) now since p3 then we know that p1 is an even number therefore we know that p12 therefore we have (p1)p2p12p0(modp) which shows that (1p+2p+3p++(p1)p) % p=0
If a Doesn't Divide p Then Fermats Little Theorem and Fermats Little Helper are Equivalent
Suppose that p2 is prime and a such that pa then ap11apa(modp)
Suppose that ap11 then multiply both sides by a. Suppose that apa since gcd(a,p)=1 then ap11(modp) as needed.
Almost Prime
Show that for any a we have a9a(mod30)

Recall that 30=235, what we will is that we will consider the equations xa(mod2,3,5), trivially for each equation x=a works, and therefore by the chinese remainder theorem any other solution is congruent to a mod 30. Our goal will be to show that a9 also satisfies the equations which will allow us to deduce that a9a(mod30)

Lets confirm that a9a(mod2), we do know that a2a(mod2) so that a9(a2)4a1aa as needed. We take a similar approach to a9 mod 3 since we know that a3a(mod3) then a9=(a3)3a, finally for a9 mod 5 we have a9=a5a4aa4a5a as needed.

Therefore we've deduced that x=a9 is also a solution, and therefore a9a(mod30)

Carmichael
We say that n1 is carmichael if ana(modn) for every a, and n is not a prime.
561 is Carmichael
As per title.

Our goal is to show that for any a we have a561a(mod561), we also have to show that n is not a prime, which is true because 561=31117. Refocusing on the initial goal, we will prove this is true by considering the equations xa(mod11,13,17) and noting that x=a is a solution, and also showing that x=a561is also a solution, and therefore concluding a561a(mod31117) by the chinese remainder theorem.

Note that if d|a then d|a561 and therefore a561a(modd) therefore applying that idea to d=3,11,17 we see that if any of them divide a we immediately obtain a561a(modd).

Otherwise things still work, for if 3a then we know that a21(mod3) since 560 is even then a560(a2)2801 so we have a561a(mod3). Similarly if 11a then a101(mod11) and therefore a5601 so that a561a(mod11). Finally if 17a then we have a161(mod17) and a560(a16)351 so that a561a(mod17).

What we've shown is that no matter what we have that a561a(mod3,11,17) and therefore by our original paragraph we are done.

Korselt's Criterion
n1 is Carmichael if and only if n is squarefree and for every prime p such that p|np1|n1.
1729 is Carmichael
As per title.
As it turns out 1729=7139, therefore it is square free and since 6,12,8|1728 then it is carmichael
Fermats Compositeness Test
Suppose n,a such that gcd(a,n)=1 then if an1≢1(modn) then n is composite
Observe the contrapositive of fermats little helper which states that ap1≢1(p|ap is not prime ) from this we conclude that (p|ap is not prime ) but since gcd(a,n)=1 then na therefore we must conclude that n is not prime, and therefore 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,a 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.

Firstly we note that 341 is divisible by 11 because 34+1=0 and therefore 341=1131 now we'll verify that 23401(mod341), note that 3413=1023 and since 210=1024 so that 10241(mod341) thus we know that 2101(mod341) therefore 3340(310)341(mod341).

On the other hand 3341≢3(mod341), we can see this is true by using the chinese remainder theorem on the equations x3(mod11) and x3(mod31) and noting that 341 solves it, but also the switch summation also solves it but the switch is not congruent to 3, so it works.

Fermat Primality Test
Let n2, and define the following function f(X):
  1. if X= return T
  2. let aX
  3. if an1≢1(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 n1 is Carmichael, then using the Fermat Primality Test, it is a probable prime.
Since n is Carmichael we know that ana(modn) for any a, during the test each a has the property that gcd(a,n)=1 therefore an11(modn), this means at each stage in the test line 4 is reached until it terminates at line 1 and returning T therefore n is a probable prime.
At Least Half of the Tested Elements will be Witnesses to a Composite Non-Carmichael Number
Suppose that n1 is composite and not Carmichael and let G={g[1,,n1]:gcd(g,n)=1} and W={wG:wn1≢1(modn)}, then |W||G|2

To prove this true, we will consider the set L={lG:ln11(modn)}, and note that G=LW then if we are able to show that |L||W| then we have |G||L|+|W|2|W| and we would deduce that |W||G|2

Since L[0,,n1] then all elements are incongruent mod n, let wWG this can be done because W is non-empty as n is not carmichael so that there exists an element gG such that gn1≢1(modn).

Since gcd(w,n)=1 then the collection of elements wL={wl:lL} are also incongruent mod n, since equality implies congruent, then non-congruent implies not equal, and therefore wL generates a collection of unique elements, so that |L|=|wL|.

But note, given some wlwL we have that (wl)n1wn1ln1wn1≢1(modn) therefore we deduce that wLW so then |wL|L therefore |L||W|, so that by our introductory paragraph, we've proven what we needed to.

Every Odd Number is a Difference of Squares
For any n1 that is odd there exists x,y1 such that n=x2y2
Since n is odd, then there is some k such that n=2k+1, note that 2k+1 is similar to (k+1)2=k2+2k+1 and so that 2k+1=(k+1)2k2 as needed. Note that in this proof k=n12 and k+1=n+12 so we are really saying that n=(n+12)2+(n12)2
The Sum is less than or Equal to the Product
Suppose that a,b2 then a+bab if a<b or b<a then a+b<ab
Suppose that a,b2 and without loss of generality assume that ab therefore a+bb+b2bab Now suppose that a<b a+b<b+b=2bab
Fermats Factorization
Suppose that n2 is odd, then n is composite iff there exists x,y1 such that n=x2y2 where xn+12

We can't use the fact that every odd number is a difference of squares, this is because the solution to that equation was specifically x=n+12 which is explicitly disallowed for this proposition, therefore instead we note that n is composite so there exists c,d[2,,n1] such that n=cd. But at the same time, we know that (c+d2)2(cd2)2amp;=c2+2cd+d2c2+2cdd24=cd We'll now prove that c+d2n+12.

Since c,d2 then we know that c+dcd=n so that c+d<n+1 therefore c+d2n+12 as needed.

Suppose that n=x2y2 since n2 then we know x>y also note that x2y2=(x+y)(xy) therefore (x+y)|n and (xy)|n, if n were to be prime, then (x+y),(xy){1,n} without loss of generality suppose that xy=1 and x+y=n therefore 2x=n+1 so x=n+12 then y=n12 which is a contradiction, and therefore n must be composite.

            
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}")