The Wayback Machine - https://web.archive.org/web/20240627104139/https://www.geeksforgeeks.org/number-theory-interesting-facts-and-algorithms/
Open In App

Number Theory (Interesting Facts and Algorithms)

Last Updated : 16 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Questions based on various concepts of number theory and different types of number are quite frequently asked in programming contests. In this article, we discuss some famous facts and algorithms:

Interesting Facts of Number Theory :

1. All 4 digit palindromic numbers are divisible by 11.

2. If we repeat a three-digit number twice, to form a six-digit number. The result will be divisible by 7, 11 and 13, and dividing by all three will give your original three-digit number.

3. A number of form 2N has exactly N+1 divisors. For example 4 has 3 divisors, 1, 2 and 4.

4. To calculate sum of factors of a number, we can find the number of prime factors and their exponents. Let p1, p2, … pk be prime factors of n. Let a1, a2, .. ak be highest powers of p1, p2, .. pk respectively that divide n, i.e., we can write n as n = (p1a1)*(p2a2)* … (pkak).

Sum of divisors = (1 + p1 + p12 ... p1a1) * 
(1 + p2 + p22 ... p2a2) *
.............................................
(1 + pk + pk2 ... pkak)

We can notice that individual terms of above
formula are Geometric Progressions (GP). We
can rewrite the formula as.

Sum of divisors = (p1a1+1 - 1)/(p1 -1) *
(p2a2+1 - 1)/(p2 -1) *
..................................
(pkak+1 - 1)/(pk -1)

5. For a product of N numbers, if we have to subtract a constant K such that the product gets its maximum value, then subtract it from a largest value such that largest value-k is greater than 0. If we have to subtract a constant K such that the product gets its minimum value, then subtract it from the smallest value where smallest value-k should be greater than 0

6. Goldbach’s conjecture: Every even integer greater than 2 can be expressed as the sum of 2 primes.

7. Perfect numbers or Amicable numbers: Perfect numbers are those numbers which are equal to the sum of their proper divisors. Example: 6 = 1 + 2 + 3

8. Lychrel numbers: Are those numbers that cannot form a palindrome when repeatedly reversed and added to itself. For example 47 is not a Lychrel Number as 47 + 74 = 121

9. Lemoine’s Conjecture : Any odd integer greater than 5 can be expressed as a sum of an odd prime (all primes other than 2 are odd) and an even semiprime. A semiprime number is a product of two prime numbers. This is called Lemoine’s conjecture.

10. Fermat’s Last Theorem : According to the theorem, no three positive integers a, b, c satisfy the equation, a^n + b^n = c^n   for any integer value of n greater than 2. For n = 1 and n = 2, the equation have infinitely many solutions.

Number Theory Algorithms

GCD and LCM 

Recent Articles on GCD and LCM!

Prime Factorization and Divisors :

Recent Articles on Prime Factors!

Fibonacci Numbers:

Recent Articles on Fibonacci Numbers!

Catalan Numbers :

Recent Articles on Catalan Numbers!

Modular Arithmetic :

Recent Articles on Modular Arithmetic!

Euler Totient Function:

nCr Computations:

Chinese Remainder Theorem: 

Factorial:



Previous Article
Next Article

Similar Reads

C++ bitset interesting facts
Bitset is a container in C++ Standard Template Library for dealing with data at the bit level. 1. A bitset stores bits (elements with only two possible values: 0 or 1). We can however get the part of a string by providing positions to bitset constructor (Positions are with respect to string position from left to right) Example: C/C++ Code // C++ pr
4 min read
Interesting Facts in C Programming | Set 2
Below are some more interesting facts about C programming: 1. Macros can have unbalanced braces: When we use #define for a constant, the preprocessor produces a C program where the defined constant is searched and matching tokens are replaced with the given expression. Example: C/C++ Code #include <stdio.h> // Declaring Macro // with
2 min read
Interesting facts about Fibonacci numbers
We know Fibonacci number, Fn = Fn-1 + Fn-2. First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, .... . Here are some interesting facts about Fibonacci number : 1. Pattern in Last digits of Fibonacci numbers : Last digits of first few Fibonacci Numbers are : 0, 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0
15+ min read
Interesting Examples of algorithms in everyday life
Ever found shortest path from Place A to Place B on Google Maps? Ever rolled a dice just by a click in an online game? Ever used search functionality in a website? One thing which is common to all these scenarios is that one or other algorithm is being run and results are being delivered. Simply stated, Algorithm is a set of instructions to reach a
2 min read
Handshaking Lemma and Interesting Tree Properties
Introduction Trees are an important concept in graph theory, and understanding their properties is crucial in solving many graph-related problems. In this article, we will explore two important properties of trees - the Handshaking Lemma and interesting tree properties. What is Handshaking Lemma? Handshaking lemma is about an undirected graph. In e
5 min read
Interesting interview question on hashCode and equals method
Prerequisite: Equal and Hashcode Methods in Java , Why to override equal and hashcode methods hashCode and equals method are frequently asked in Java interviews. In general, we do not override both methods but there are some scenarios/requirements when we have to override these two methods. One such scenario when we store user-defined objects in Co
4 min read
Some interesting shortest path questions | Set 1
Question 1: Given a directed weighted graph. You are also given the shortest path from a source vertex 's' to a destination vertex 't'. If weight of every edge is increased by 10 units, does the shortest path remain same in the modified graph? The shortest path may change. The reason is, there may be different number of edges in different paths fro
3 min read
Program to print interesting pattern
Program to print following pattern: ********1******** *******2*2******* ******3*3*3****** *****4*4*4*4***** ****5*5*5*5*5**** ***6*6*6*6*6*6*** **7*7*7*7*7*7*7** Examples : Input : 4 Output : ********1******** *******2*2******* ******3*3*3****** *****4*4*4*4***** Input :5 Output : ********1******** *******2*2******* ******3*3*3****** *****4*4*4*4**
10 min read
Generate a list of n consecutive composite numbers (An interesting method)
Given a number n, generate a list of n composite numbers.Examples: Input : 5 Output : 122, 123, 124, 125 Input : 10 Output : 3628802, 3628803, 3628804, 3628805, 3628806, 3628807, 3628808, 3628809, 3628810 The idea here is using the properties of [Tex]n! [/Tex]. Since [Tex]n! = 1\times2\times3....(n-1)\times n [/Tex], then numbers [Tex]1, 2, 3.....
4 min read
Count of interesting primes upto N
Given a number N, the task is to find the number of interesting primes less than equal to N.An interesting prime is any prime number which can be written as a2 + b4, where a and b are positive integers. For e.g. The smallest interesting prime number is 2 = 12 + 14. Examples: Input: N = 10 Output: 2 2 = 12 + 14 5 = 22 + 14 Both are interesting prime
15 min read
three90RightbarBannerImg