Many people would think that the investigation of such things as prime numbers is irrelevant to society. In fact, number theorist, G. H. Hardy justified pure mathematics on the basis of the purity it derives from its irrelevance.
In his landmark publication, A Mathematician’s Apology, Hardy was unapologetic about the fact that number theory, unlike applied mathematics, had no real application to anything of use, and he asserted:
The “real” mathematics of the “real” mathematicians, the mathematics of Fermat and Euler and Gauss and Abel and Riemann, is almost wholly “useless,” …, and both Gauss and lesser mathematicians may be justified in rejoicing that there is one science, … , whose very remoteness from ordinary human activities should keep it gentle and clean.
Ironically, the RSA cryptosystem, developed in the 1970’s, that was based on such “useless” ideas as large prime numbers, found extensive use by financial institutions in protecting confidential information. In fact, as we moved into the information age, cryptography and number theoretic techniques came to the forefront of important applications in mathematics.
So, while a case can be made to justify pure mathematics on the basis of its potential uses, we can also justify pure mathematics for its innate value beyond its potential applications.
In this link, Sridhar provides some excellent insights. Sridhar Mahadevan’s answer to What is the point of pure mathematics?