Solving Diophantine Equations

Solving Diophantine Equations

Octavian Cira and Florentin Smarandache


In recent times the we witnessed an explosion of Number Theory problems that are solved using mathematical software and powerful computers. The observation that the number of transistors packed on integrated circuits doubles every two years made by Gordon E. Moore in 1965 is still accurate to this day. With ever increasing computing power more and more mathematical problems can be tacked using brute force. At the same time the advances in mathematical software made tools like Maple, Mathematica, Matlab or Mathcad widely available and easy to use for the vast majority of the mathematical research community. This tools don’t only perform complex computations at incredible speeds but also serve as a great tools for symbolic computation, as proving tools or algorithm design.

The online meeting of the two authors lead to lively exchange of ideas, solutions and observation on various Number Theory problems. The ever increasing number of results, solving techniques, approaches, and algorithms led to the the idea presenting the most important of them in in this volume. The book offers solutions to a multitude of –Diophantine equation proposed by Florentin Smarandache in previous works (Smarandache, 1993, 1999b, 2006) over the past two decades. The expertise in tackling Number Theory problems with the aid of mathematical software such as (Cira and Cira, 2010), (Cira, 2013, 2014a; Cira and Smarandache, 2014; Cira, 2014b, c, d, e) played an important role in producing the algorithms and programs used to solve over –Diophantine equation. There are numerous other important publications related to Diophantine Equations that offer various approaches and solutions. However, this book is different from other books of number theory since it dedicates most of its space to solving Diophantine Equations involving the Smarandache function. A search for similar results in online resources like The On-Line Encyclopedia of Integer Sequences reveals the lack of a concentrated effort in this direction.

The brute force approach for solving –Diophantine equation is a well known technique that checks all the possible solutions against the problem constrains to select the correct results. Historically, the proof of concept was done by Appel and Haken (1977) when they published the proof for the four color map theorem. This is considered to be the the first theorem that was proven using a computer. The approach used both the computing power of machines as well as theoretical results that narrowed down infinite search space to map configurations that had to be check. Despite some controversy in the ’80 when a masters student discovered a series of errors in the discharging procedure, the initial results was correct. Appel and Haken went on to publish a book (Appel and Haken, 1989) that contained the entire and correct prof that every planar map is four-colorable.

Recently, in 2014 an empirical results of Goldbach conjecture was published in Mathematics of Computation where Oliveira e Silva et al. (2013), (Oliveira e Silva, 2014), confirm the theorem to be true for all even numbers not larger than .

The use of Smarandache function that involves the set of all prime numbers constitutes one of the main reasons why, most of the problems proposed in this book do not have a finite number of cases. It could be possible that the unsolved problems from this book could be classified in classes of unsolved problems, and thus solving a single problem will help in solving all the unsolved problems in its class. But the authors could not classify them in such classes. The interested readers might be able to do that. In the given circumstances the authors focused on providing the most comprehensive partial solution possible, similar to other such solutions in the literature like:

  • Goldbach’s conjecture. In 2003 Oliveira e Silva announced that all even numbers can be expressed as a sum of two primes. In 2014 the partial result was extended to all even numbers smaller then , (Oliveira e Silva, 2014).

  • For any positive integer , let denote the number of solutions to the Diophantine equation with , , positive integers. The Erdős-Straus conjecture, (Obláth, 1950; Rosati, 1954; Bernstein, 1962; Tao, 2011), asserts that for every . Swett (2006) established that the conjecture is true for all integers for any . Elsholtz and Tao (2012) established some related results on and related quantities, for instance established the bound for all primes .

  • Tutescu (1996) stated that for any . On March 3rd, 2003 Weisstein published a paper stating that all the relation is valid for all numbers up to , (Sondow and Weisstein, 2014).

  • A number is –hyperperfect for some integers if , where is the sum of the proper divisors of . All –hyperperfect numbers less than have been computed. It seems that the conjecture ”all hyperperfect numbers for odd are of the form , with prime and prime” is false (McCranie, 2000).

This results do not offer the solutions to the problems but they are important contributions worth mentioning.

The emergence of mathematical software generated a new wave of mathematical research aided by computers. Nowadays it is almost impossible to conduct research in mathematics without using software solutions such as Maple, Mathematica, Matlab or Mathcad, etc. The authors used extensively Mathcad to explore and solve various Diophantine equations because of the very friendly nature of the interface and the powerful programming tools that this software provides. All the programs presented in the following chapters are in their complete syntax as used in Mathcad. The compact nature of the code and ease of interpretation made the choice of this particular software even more appropriate for use in a written presentation of solving techniques.

The empirical search programs in this book where developed and executed in Mathcad. The source code of this algorithms can be interpreted as pseudo code (the Mathcad syntax allows users to write code that is very easy to read) and thus translated to other programming languages.

Although the intention of the authors was to provide the reader with a comprehensive book some of the notions are presented out of order. For example the book the primality test that used Smarandache’s function is extensively used. The first occurrences of this test preceded the definition the actual functions and its properties. However, overall, the text covers all definition and proves for each mathematical construct used. At the same time the references point to the most recent publications in literature, while results are presented in full only when the number of solutions is reasonable. For all other problems, that generate in excess of double, triple or quadruple pairs, only partial results are contained in the sections of this book. Nevertheless, anyone interested in the complete list should contact the authors to obtain a electronic copy of it. Running the programs in this book will also generate the same complete list of possible solutions for any odd the problems in this book.



We would like to thank all the collaborators that helped putting together this book, especially to Codruţa Stoica and Cristian Mihai Cira, for the important comments and observations.



A Diophantine equation is a linear equation where and the solutions and are also integer numbers. This equation can be completely solved by the well known algorithm proposed by Brahmagupta (Weisstein, 2014b).

In 1900, Hilbert wondered if there is an universal algorithm that solves the Diophantine equation, but Matiyasevich (1970) proved that such an algorithm does not exist for the first order solution.

The function relates to each natural number the smallest natural number such that is a multiple of . In this book we aim to find analytical or empirical solutions to Diophantine and –Diophantine equation, namely Diophantine equation that contain the Smarandache’s function, Smarandache (1980b).

An analytical solution implies a general solution that completely solves the problem. For example, the general solution for the equation , with is and , where is a particular solution, and is an integer, .

By and empirical solution we understand a set of algorithms that determine the solutions of the Diophantine equation within a finite domain of integer numbers, dubbed the search domain to dimension . For example, the –Diophantine equation over the valid search domain of dimension , the solutions could be the triplets .

The first chapter introduces concepts about prime numbers, primality tests, decomposition algorithms for natural numbers, counting algorithms for all natural numbers up to a real one, etc. This concepts are fundamental for validating the empirical solutions of the –Diophantine equations.

The second chapter introduces the function along side its known properties. This concepts allow the description of Kempner (1918) algorithm that computes the function. The latter sections contain the set of commands and instructions that generate the file which contains the values for .

The third chapter describes the division functions , , usually denoted by , and . The function counts the number of divisors of , while returns the sum of all those divisors. Consequently computed the sum of squared divisors of while, in general add all divisors to the power of . We call divisors of all natural numbers that divide including and , thus the proper divisors are considered all natural divisors excluding itself. In this case the function is , in fact, the sum of all proper divisors. Along side the the definition, this third chapter also contains the properties and computing algorithms that generate the files , , , that contain all the values for functions , , and for . The last section describes the –perfect numbers.

Euler’s totient function also known as the function that counts the natural numbers less than or equal to that are relatively prime is described in chapter . As an example, for the relatively prime factors are , , , and because 111where is that is the greatest common divisor of and , , , and , thus . The chapter also describes the most important properties of this function. The latter section of the chapter contain the algorithm that generates the file that contains the values of the function for raging from . Also, in this chapter the describes a generalization of Euler theorem relative to the totient function and the algorithm the computes the pair that verifies the Diophantine equation , where .

In chapter 5 we define a function which will allow us to (separately or simultaneously) generalize many theorems from Number Theory obtained by Wilson, Fermat, Euler, Gauss, Lagrange, Leibniz, Moser, and Sierpinski.

Various analytical solutions to Diophantine equations such as: the second degree equation, the linear equation with unknown, linear systems, the degree equation with one unknown, Pell general equation, and the equation . For each of this cases, in chapter six we present symbolic computation that ensure the detection of the solutions for the particular Diophantine equations.

Chapter seven describes the solutions to the –Diophantine equations using the search algorithms in the search domains.

The Conclusions and Index section conclude the book.

Chapter 1 Prime numbers

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than and itself. A natural number greater than 1 that is not a prime number is called a composite number. For example, is prime because and are its only positive integer factors, whereas is composite because it has the divisors and in addition to and . The fundamental theorem of Arithmetics, (Hardy and Wright, 2008, p. 2-3), establishes the central role of primes in the Number Theory: any integer greater than can be expressed as a product of primes that is unique up to ordering. The uniqueness in this theorem requires excluding as a prime because one can include arbitrarily many instances of in any factorization, e.g., , , , etc. are all valid factorizations of , (Estermann, 1952; Vinogradov, 1955).

The property of being prime (or not) is called primality. A simple but slow method of verifying the primality of a given number is known as trial division. It consists of testing whether is a multiple of any integer between and . The floor function , also called the greatest integer function or integer value (Spanier and Oldham, 1987), gives the largest integer less than or equal to . The name and symbol for the floor function were coined by Iverson, (Graham et al., 1994). Algorithms much more efficient than trial division have been devised to test the primality of large numbers. Particularly fast methods are available for numbers of special forms, such as Mersenne numbers. As of April 2014, the largest known prime number has decimal digits (Caldwell, 2014a).

There are infinitely many primes, as demonstrated by Euclid around 300 BC. There is no known useful formula that sets apart all of the prime numbers from composites. However, the distribution of primes, that is to say, the statistical behavior of primes in the large, can be modelled. The first result in that direction is the prime number theorem, proven at the end of the 19th century, which says that the probability that a given, randomly chosen number is prime is inversely proportional to its number of digits, or to .

Many questions around prime numbers remain open, such as Goldbach’s conjecture, and the twin prime conjecture, Diophantine equations that have integer functions. Such questions spurred the development of various branches of the Number Theory, focusing on analytic or algebraic aspects of numbers. Prime numbers give rise to various generalizations in other mathematical domains, mainly algebra, such as prime elements and prime ideals.

1.1 Generating prime numbers

The generation of prime numbers can be done by means of several deterministic algorithms, known in the literature, as sieves: Sieve of Eratosthenes, Sieve of Euler, Sieve of Sundaram, Sieve of Atkin, etc. In this volume we will detail only the most efficient prime number generating algorithms.

The Sieve of Eratosthenes is an algorithm that allows the generation of all prime numbers up to a given limit . The algorithm was given by Eratosthenes around 240 BC.

Program 1.1.

Let us consider the origin of vectors and matrices , which can be defined in Mathcad by assigning . The Sieve of Eratosthenes in the linear variant of Pritchard, presented in pseudo code in the article (Pritchard, 1987), written in Mathcad is:                               It is well known that the segmented version of the Sieve of Eratosthenes, with basic optimizations, uses operations and

bits of memory, (Pritchard, 1987, 1994).

Table 1.1: The vector in the code 1.1

The linear variant of the Sieve of Eratosthenes implemented by Pritchard, given by the code 1.1, has the inconvenience that is repeats uselessly operations. For example, for , in table (1.1) is given the binary vector which contains at each position the values or . On the first line is the index of the vector.

  1. Initially, all the positions of vector have the value .

  2. For the algorithm puts on all the positions multiple of , for .

  3. For the algorithm puts on all the positions multiple of , for , which means positions , , , , and but positions , and were already annulated in the previous step.

  4. For the algorithm puts on all the positions multiple of , for , which means positions , , , but these positions were annulated also in the second step, and on position is taken for the third time.

  5. For one takes .

Eventually, vector is read. The index of vector , which has the value , is a prime number. If we count the number of attributing the value , we remark that this operation was made time. It is obvious that these repeated operations make the algorithm less efficient.

Program 1.2.

This program is a better version of program 1.1 because it puts only on the odd positions of the vector .                        

Program 1.3.

This program is a better version of program 1.2 because it uses a minimal memory space.                          

Even the execution time of the program 1.3 is a little longer than of the program 1.2, the best linear variant of the Sieve of Eratosthenes is the program 1.3, as it provides an important memory economy ( memory locations instead of , the amount of memory locations used by programs 1.1 and 1.2).

Program 1.4.

The program for the Sieve of Eratosthenes, Pritchard variant, was improved in order to allow the number of repeated operations to diminish. The improvement consists in the fact that attributing is done for only odd multiples of prime numbers. The program has a restriction, but which won’t cause inconveniences, namely must be a integer greater than .                                                

We remark that it is not necessary to put on each positions , as in the original version of the program 1.1, because the sum of two odd numbers is an even number and the even positions are not considered. In this moment of the program we are sure that the positions from to of the vector is_prime (from 2 in 2) which were left on (which means that their indexes are prime numbers), can be added to the prime numbers vector. Hence, instead of building the vector at the end of the markings, we do it in intermediary steps. The advantage consists on the fact that we have a list of prime numbers which can be used to obtain the other primes, up to the given limit .

Program 1.5.

The program that improves the program CEPb by halving the used memory space.                                                  

The performances of the 5 programs can be observed on the following execution sequences (the call of the programs have been done on the same computer and in similar conditions):

  1. Call of the program CEP1.1, i.e. the Sieve of Eratosthenes in the linear version of Pritchard

  2. Call of the program CEPm1.3,

  3. Call of the program CEPi1.2,

  4. Call of the program CEPb1.4,

  5. Call of the program CEPbm1.5,

In the comparative table 1.2 are presented the attributions of , the execution times on a computer with a processor Intel of 2.20GHz with RAM of 4.00GB (3.46GB usable) and the number of memory units for the programs 1.1, 1.3, 1.2, 1.4 and 1.5.

program Attributions of Execution time Memory used
1.1 71 760 995 28.238 sec 21 270 607
1.3 35 881 043 10.920 sec 11 270 607
1.2 35 881 043 7.231 sec 21 270 607
1.4 18 294 176 5.064 sec 21 270 607
1.5 18 294 176 7.133 sec 11 270 607
Table 1.2: Comparative table

The Sieve of Sundaram is a simple deterministic algorithm for finding the prime numbers up to a given natural number. This algorithm was presented by Sundaram and Aiyar (1934). As it is known, the Sieve of Sundaram uses operations in order to find the prime numbers up to . The algorithm of the Sieve of Sundaram in pseudo code Mathcad is:                           The Call of the program CS

Until recently, i.e. till the appearance of the Sieve of Atkin, (Atkin and Bernstein, 2004), the Sieve of Eratosthenes was considered the most efficient algorithm that generates all the prime numbers up to a limit . The figure 1.1 emphasize the graphic representation of the ratio between the number of operations needed for the Sieve of Eratosthenes, , and the number of operations needed for the Sieve of Atkin, , for . In this figure one can see that the Sieve of Atkin is better (relative to the number of operations needed by the program) then the Sieve of Eratosthenes, for .

Figure 1.1: The ratio of the numbers of operations
Program 1.6.

The Sieve of Atkin in pseudo code presented in Mathcad is:                                                

As it is known, this algorithm uses only simple operations and memory locations, (Atkin and Bernstein, 2004).

Our implementation, in Mathcad, of Atkin’s algorithm contains some remarks that make more performance program than the original algorithm.

  1. Except all even numbers are not prime, it follows that, with the initialization for , there is no need to change the values of these components. Consequently, we will change only the odd components.

  2. If is odd then is always odd. It follows that the sequence


    assures that the number is always odd.

  3. If and have different parities, Then is odd. Then the sequence


    assures that is odd.

  4. If and and have different parities, then is odd. Then the sequence


    assures that is odd.

  5. Similarly as in 1, we will eliminate only the perfect squares for odd numbers , because only these are odd.

Program 1.7.

AO program (Atkin optimized) of generating prime numbers up to .                                               In this program function was used (which means ) instead of function (which means ) in formulas (1.1), (1.2) and (1.3), in order to avoid errors of floating comma which could determine the loss of cases at limit , for example, when is a perfect square.

  1. Call of the program 1.6 the Sieve of

  2. Call of the program 1.7 the optimized Sieve of

There exists an implementation for the Sieve of Atkin, due to Bernstein (2014) under the name Primgen. Primegen is a library of programs for fast generating prime numbers, increasingly. Primegen generates all prime numbers up to in only 8 seconds on a computer with a Pentium II-350 processor. Primegen can generate prime numbers up to .

1.2 Primality tests

A central problem in the Number Theory is to determine weather an odd integer is prime or not. The test than can establish this is called primality test.

Primality tests can be deterministic or non-deterministic. The deterministic ones establish exactly if a number is prime, while the non-deterministic ones can falsely determine that a composite number is prime. These test are much more faster then the deterministic ones. The numbers that pass a non-deterministic primality test are called probably prime (this is denoted by prime?) until their primality is deterministically proved. A list of probably prime numbers are Mersenne’s numbers, (Caldwell, 2014b):

  • , Dec. 2005 – Curtis Cooper and Steven Boone,

  • , Sept. 2006 – Curtis Cooper and Steven Boone,

  • , Sept. 2008 – Hans-Michael Elvenich,

  • , Apr. 2009 – Odd Magnar Strindmo,

  • , Aug. 2008 – Edson Smith,

  • , Jan. 2013 – Curtis Cooper.

1.2.1 The test of primality

As seen in Theorem 2.3, we can use as primality test the computing of the value of function. For , if relation is satisfied, it follows that is prime. In other words, the prime numbers (to which number is added) are fixed points for function. In this study we will use this primality test.

Program 1.8.

The program for primality test. The program returns the value if the number is not prime and the value if the number is prime. File is read and assigned to vector  .


By means of the program 1.8 was realized the following test.

The number of prime numbers up to is , and the sum of non-zero components (equal to 1) is , as was not counted as prime number because it is an even number. We remark that the time needed by the primality test of all odd numbers is a much more better time than the necessary for the primality test 1.11 on a computer with an Intel processor of 2.20GHz with RAM of 4.00GB (3.46GB usable).

1.2.2 Deterministic tests

Proving that an odd number is prime can be done by testing sequentially the vector that contains prime numbers.

The browsing of the list of prime numbers can be improved by means of the function that counts the prime numbers (Weisstein, 2014e). Traditionally, by is denoted the function that indicates the number of prime numbers , (Shanks, 1962, 1993, p. 15). The notation for the function that counts the prime numbers is a little bit inappropriate as it has nothing to do with , The universal constant that represents the ratio between the length of a circle and its diameter. This notation was introduced by the number theorist Edmund Landau in 1909 and has now become standard, (Landau, 1958) (Derbyshire, 2004, p. 38). We will give a famous result of Rosser and Schoenfeld (1962), related to function . Let functions given by formulas



Theorem 1.9.

Following inequalities


hold, for all , the right side inequality, and for all the left side inequality.


See (Rosser and Schoenfeld, 1962, T. 1). ∎

Let functions be defined by formulas:


where is the lower integer part function and is the upper integer part function. As a consequence of Theorem 1.9 we have

Theorem 1.10.

Following inequalities


hold, for all , where by is denoted the set of natural odd numbers.


As function for all , it results, according to Theorem 1.9, that the right side inequality is true for all , hence, also for .

Figure 1.2: Functions , and

As for all , and the left side inequality (1.6) holds for all , it follows that the left side inequality (1.9) holds for all .

For we have: