Questions tagged [number-theory]
Number theory involves properties and relationships of numbers, primarily positive integers.
378
questions
17
votes
4answers
2k views
Calculate practical numbers
Definition
A positive integer n is a practical number (OEIS sequence A005153) iff all smaller positive integers can be represented as sums of distinct divisors of <...
14
votes
12answers
2k views
Print n weird numbers
A weird number is a number that the sum of proper divisors is greater than the number itself and no subset of proper divisors sum to that number.
Examples:
70 is a weird number because its proper ...
7
votes
7answers
977 views
Count how many numbers are divisible by perfect numbers in a given range
Given two arbitrary integers \$a\$ and \$b\$, count how many numbers are divisible by perfect numbers in that given range (\$a\$ and \$b\$ both are inclusive).
In mathematics, a perfect number is a ...
18
votes
7answers
1k views
Period of the decimal representation
Write a function which takes a single positive integer n and returns the period of the decimal representation of 1/n.
Test cases:
...
14
votes
6answers
792 views
Hardy–Ramanujan number generalization
\$1729\$, known as the Hardy–Ramanujan number, is the smallest positive integer that can be expressed as the sum of two cubes of positive integers in two ways (\$12^3+1^3=10^3+9^3=1729\$). Given an ...
6
votes
9answers
4k views
List the first 20 friendly number pairs
I just started reading about friendly numbers and I think they sound great.
In number theory, friendly numbers are two or more natural numbers with a common abundancy, the ratio between the sum of ...
4
votes
1answer
312 views
Decompose a range in aligned blocks of size 2^n [closed]
Given an arbitrary contiguous range of positive integers, find the decomposition in the minimum number of sub-ranges of size L = 2^n, with the constraint that each range must be aligned, that is the ...
14
votes
11answers
1k views
N Doors, K Monkeys
There are N doors and K monkeys. Initially, all the doors are closed.
Round 1: The 1st monkey visits every door and toggles the door (if the door is closed, it gets opened it; if it is open, it gets ...
7
votes
7answers
1k views
Nth K-Ugly Number
Write the shortest code in any language of your choice to find the \$N\$th \$K\$-ugly number.
A \$K\$-ugly number is a number whose only prime factors are the prime numbers \$\le K\$.
\$K\$-ugly ...
6
votes
18answers
1k views
Evaluate the primorial of a number [duplicate]
The primorial of a number is the product of all the primes until that number, itself included.
Take a number from STDIN as the input and evaluate its primorial, ...
6
votes
3answers
2k views
The making of “Spot It!”: Finding almost unique sets
Puzzle: Find a deck of c cards, each containing p pictures, such that no two pictures match on a given card, and exactly 1 picture on each card matches exactly 1 picture on each of the other cards, ...
21
votes
5answers
2k views
Find largest prime which is still a prime after digit deletion
Over at https://math.stackexchange.com/questions/33094/deleting-any-digit-yields-a-prime-is-there-a-name-for-this the following question is asked. How many primes are there that remain prime after you ...
11
votes
6answers
767 views
Bijection between binary strings and pairs thereof
Input: Either one or two strings consisting of '0's and '1's. If there are 2, they are separated by a space. All strings are of ...
4
votes
2answers
513 views
List ALL prime-factorized natural numbers in ANY order
This is a variant of List prime-factorized natural numbers up to N in ascending order, but the solutions can be very different.
Write a program that outputs prime factorizations of all natural ...
8
votes
3answers
1k views
List prime-factorized natural numbers up to N in ascending order
For a given n list prime factorization of all natural numbers between 1 and n in ascending ...
19
votes
19answers
3k views
Calculate hamming weight with low hamming weight
Create a program that computes the hamming weight of a string. Winner is the program with the lowest hamming weight.
Rules:
Hamming weight for an ASCII character is defined as the total number of ...
16
votes
40answers
2k views
Undulant numbers [duplicate]
An undulant number is a number where its digits alternate between up and down like the following number: 461902 or 708143, or even 1010101, but not 123, because
2 < 3.
Write a program or function ...
7
votes
14answers
749 views
Another amicable number problem
Two numbers are said to be 'amicable' or 'friends' if the sum of the proper divisors of the first is equal to the second, and viceversa. For example, the proper divisors of 220 are: 1, 2, 4, 5, 10, ...
17
votes
8answers
902 views
Square Number Digit Density
The square number digit density (SNDD) of a number - invented by myself - is the ratio of the count of square numbers found in consecutive digits to the length of the number. For instance, 169 is a 3-...
24
votes
24answers
3k views
Find the prime factors
In this task, you have to write a program, that computes the prime factors of a number. The input is a natural number 1 < n < 2^32. The output is a list of the prime factors of the number in the ...
8
votes
4answers
865 views
Greatest greatest common divisor
Find the greatest gcd of the numbers \$n^m + k\$ and \$(n+1)^m + k\$ for given m and k.
For example, for ...
16
votes
9answers
876 views
Last k digits of Powers of 2
For any integer \$r\$, there exists a
power of 2 each of whose last \$r\$ digits
are either 1 or 2.
Given \$r\$, find the smallest \$x\$ such that \$2^x\bmod{10^r}\$ consists of only 1 or 2.
For \$r=...
23
votes
17answers
4k views
Last non-zero digit of n!
Given an integer 1 ≤ N ≤ 1,000,000 as input, output the last non-zero digit of N!, where ! is the factorial (the product of all numbers from 1 to N, inclusive). This is OEIS sequence A008904.
Your ...
13
votes
5answers
595 views
Perfect powers in more than one way?
Challenge
Your task is to write a program or function which, given a positive integer \$N\$, finds all positive integers less than or equal to \$N\$ that can be expressed as a perfect power in more ...
6
votes
11answers
584 views
Find the largest value of power.
Some numbers can be represented as perfect powers of other numbers. A number x can be represented as x = base^power for some integer base and power.
Given an integer x you have to find the largest ...
9
votes
10answers
646 views
Find the number of x-digit numbers whose product of digits is N
Given two numbers \$N\$ and \$x\$, find the number of \$x\$-digit numbers whose product of digits is \$N\$
\$N <10^6\$ and \$x <12\$
...
18
votes
12answers
806 views
Compute modular inverse
Given two positive numbers \$x\$ and \$n\$ with \$x<2^n\$, write the shortest possible function to compute \$x^{-1} \mod 2^n\$. In other words, find \$y\$ such that \$xy=1 \mod 2^n\$.
Your ...
23
votes
6answers
4k views
Hamming numbers
Given a positive integer, print that many hamming numbers, in order.
Rules:
Input will be a positive integer \$n \le 1,000,000 \$
Output should be the first n terms of https://oeis.org/A051037
...