Number theory is a branch of mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example, rational numbers), or defined as generalizations of the integers (for example, algebraic integers).

Integers can be considered either in themselves or as solutions to equations (Diophantine geometry). Questions in number theory can often be understood through the study of analytical objects, such as the Riemann zeta function, that encode properties of the integers, primes or other number-theoretic objects in some fashion (analytic number theory). One may also study real numbers in relation to rational numbers, as for instance how irrational numbers can be approximated by fractions (Diophantine approximation).

Number theory is one of the oldest branches of mathematics alongside geometry. One quirk of number theory is that it deals with statements that are simple to understand but are very difficult to solve. Examples of this are Fermat's Last Theorem, which was proved 358 years after the original formulation, and Goldbach's conjecture, which remains unsolved since the 18th century. German mathematician Carl Friedrich Gauss (1777–1855) once remarked, "Mathematics is the queen of the sciences—and number theory is the queen of mathematics." It was regarded as the epitome of pure mathematics, with no applications outside mathematics, until the 1970s, when prime numbers became the basis for the creation of public-key cryptography algorithms, such as the RSA cryptosystem.

Definition Number theory is the branch of mathematics that studies integers and their properties and relations. The integers comprise a set that extends the set of natural numbers to include number and the negation of natural numbers . Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example, rational numbers), or defined as generalizations of the integers (for example, algebraic integers).

Number theory is closely related to arithmetic and some authors use the terms as synonyms. However, the word "arithmetic" is used today to mean the study of numerical operations and extends to the real numbers. In a more specific sense, number theory is restricted to the study of integers and focuses on their properties and relationships. Traditionally, it is known as higher arithmetic. By the early twentieth century, the term number theory had been widely adopted.The term 'arithmetic' may have regained some ground, arguably due to French influence. Take, for example, . In 1952, Davenport still had to specify that he meant The Higher Arithmetic. Hardy and Wright wrote in the introduction to An Introduction to the Theory of Numbers (1938): "We proposed at one time to change [the title] to An introduction to arithmetic, a more novel and in some ways a more appropriate title; but it was pointed out that this might lead to misunderstandings about the content of the book." The term number means whole numbers, which refers to either the natural numbers or the integers.

Elementary number theory studies aspects of integers that can be investigated using elementary methods such as elementary proofs. Analytic number theory, by contrast, relies on complex numbers and techniques from analysis and calculus. Algebraic number theory employs algebraic structures such as fields and rings to analyze the properties of and relations between numbers. Geometric number theory uses concepts from geometry to study numbers. Further branches of number theory are probabilistic number theory, combinatorial number theory, computational number theory, and applied number theory, which examines the application of number theory to science and technology.

History

In recorded history, knowledge of numbers existed in the ancient civilisations of Mesopotamia, Egypt, China, and India. The earliest historical find of an arithmetical nature is the Plimpton 322, dated c. 1800 BC. It is a broken clay tablet that contains a list of Pythagorean triples, that is, integers such that . The triples are too numerous and too large to have been obtained by brute force.. The term is problematic. Robson prefers the rendering "The holding-square of the diagonal from which 1 is torn out, so that the short side comes up...". The table's layout suggests that it was constructed by means of what amounts, in modern language, to the identity. Other sources give the modern formula . Van der Waerden gives both the modern formula and what amounts to the form preferred by Robson.which is implicit in routine Old Babylonian exercises.Neugebauer discusses the table in detail and mentions in passing Euclid's method in modern notation . It has been suggested instead that the table was a source of numerical examples for school problems.. This is controversial. See Plimpton 322. Robson's article is written polemically with a view to "perhaps [...] knocking [Plimpton 322] off its pedestal" ; at the same time, it settles to the conclusion that

[...] the question "how was the tablet calculated?" does not have to have the same answer as the question "what problems does the tablet set?" The first can be answered most satisfactorily by reciprocal pairs, as first suggested half a century ago, and the second by some sort of right-triangle problems .

Robson takes issue with the notion that the scribe who produced Plimpton 322 (who had to "work for a living", and would not have belonged to a "leisured middle class") could have been motivated by his own "idle curiosity" in the absence of a "market for new mathematics". Plimpton 322 tablet is the only surviving evidence of what today would be called number theory within Babylonian mathematics, though a kind of Babylonian algebra was much more developed.

Although other civilizations probably influenced Greek mathematics at the beginning, all evidence of such borrowings appear relatively late,Iamblichus, Life of Pythagoras,(trans., for example, ) cited in . See also Porphyry, Life of Pythagoras, paragraph 6, in Herodotus (II. 81) and Isocrates (Busiris 28), cited in: . On Thales, see Eudemus ap. Proclus, 65.7, (for example, ) cited in: . Proclus was using a work by Eudemus of Rhodes (now lost), the Catalogue of Geometers. See also introduction, on Proclus's reliability. and it is likely that Greek , the theoretical or philosophical study of numbers, is an indigenous tradition. Ancient Greek mathematicians conventionally separated numbers (mostly positive integers but occasionally rationals) from magnitudes or lengths, with only the former being the subject of arithmetic.

A keen interest in divisibility is found in early Greek arithmetic. Pythagoreans often attributed mystical qualities to perfect and amicable numbers, and dedicated time to the study polygonal or figurate numbers. Later, Euclid devoted part of his Elements to topics that belong to elementary number theory, including prime numbers and divisibility. He gave the Euclidean algorithm for computing the greatest common divisor of two numbers and a proof implying the infinitude of primes. Building on the works of the earlier Pythagoreans, Nicomachus of Gerasa wrote an Introduction to Arithmetic that was to be influential in later centuries, while Theon of Smyrna's Mathematics Useful For Understanding Plato discusses the idea of congruences. The most important late antique author was arguably Diophantus of Alexandria, who probably lived in the 3rd century AD. He wrote the Arithmetica, a collection of worked-out problems where the task is invariably to find rational solutions to a system of polynomial equations, usually of the form or . In modern parlance, Diophantine equations are polynomial equations to which rational or integer solutions are sought.

After the fall of Rome, development shifted to Asia, albeit intermittently. The Chinese remainder theorem appears as an exerciseSunzi Suanjing, Chapter 3, Problem 26. This can be found in , which contains a full translation of the Suan Ching (based on ). See also the discussion in . in Sunzi Suanjing (between the third and fifth centuries).The date of the text has been narrowed down to 220–420 AD (Yan Dunjie) or 280–473 AD (Wang Ling) through internal evidence (= taxation systems assumed in the text). See . The result was later generalized with a complete solution called Da-yan-shu () in Qin Jiushao's 1247 Mathematical Treatise in Nine Sections. There is also some numerical mysticism in Chinese mathematics,See, for example, Sunzi Suanjing, Ch. 3, Problem 36, in : Now there is a pregnant woman whose age is 29. If the gestation period is 9 months, determine the sex of the unborn child. Answer: Male. Method: Put down 49, add the gestation period and subtract the age. From the remainder take away 1 representing the heaven, 2 the earth, 3 the man, 4 the four seasons, 5 the five phases, 6 the six pitch-pipes, 7 the seven stars [of the Dipper], 8 the eight winds, and 9 the nine divisions [of China under Yu the Great]. If the remainder is odd, [the sex] is male and if the remainder is even, [the sex] is female. This is the last problem in Sunzi's otherwise matter-of-fact treatise. but, unlike that of the Pythagoreans, it seems to have led nowhere. While Greek astronomy probably influenced Indian learning it seems to be the case that Indian mathematics is otherwise an autochthonous tradition.Any early contact between Babylonian and Indian mathematics remains conjectural . Āryabhaṭa (476–550 AD) showed that pairs of simultaneous congruences , could be solved by a method he called kuṭṭaka, or pulveriser;Āryabhaṭa, Āryabhatīya, Chapter 2, verses 32–33, cited in: . See also . A slightly more explicit description of the kuṭṭaka was later given in Brahmagupta, Brāhmasphuṭasiddhānta, XVIII, 3–5 (in , cited in ). this is a procedure close to the Euclidean algorithm. Āryabhaṭa seems to have had in mind applications to astronomical calculations. Brahmagupta (628 AD) started the systematic study of indefinite quadratic equations—in particular, the Pell equation. A general procedure for solving Pell's equation was probably found by Jayadeva; the earliest surviving exposition appears in Bhāskara II's Bīja-gaṇita (twelfth century).

In the early ninth century, the caliph al-Ma'mun ordered translations of many Greek mathematical works and at least one Sanskrit work., cited in . See also the preface in cited in , and , cited in . Diophantus's main work, the Arithmetica, was translated into Arabic by Qusta ibn Luqa (820–912). Part of the treatise al-Fakhri (by al-Karajī, 953 – c. 1029) builds on it to some extent. According to Rashed Roshdi, Al-Karajī's contemporary Ibn al-Haytham knew what would later be called Wilson's theorem. Other than a treatise on squares in arithmetic progression by Fibonacci no number theory to speak of was done in western Europe during the Middle Ages. Matters started to change in Europe in the late Renaissance, thanks to a renewed study of the works of Greek antiquity. A catalyst was the textual emendation and translation into Latin of Diophantus' Arithmetica.Bachet, 1621, following a first attempt by Xylander, 1575

French mathematician Pierre de Fermat (1607–1665) never published his writings but communicated through correspondence and wrote in marginal notes instead. His contributions to number theory brought renewed interest in the field in Europe. He conjectured Fermat's little theorem, a basic result in modular arithmetic, and Fermat's Last Theorem, as well as proved Fermat's right triangle theorem. He also studied prime numbers, the four-square theorem, and Pell's equations.