Skip to main content

Questions tagged [number-theory]

Number theory involves properties and relationships of numbers, primarily positive integers.

Filter by
Sorted by
Tagged with
7 votes
7 answers
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 ...
Coding man's user avatar
  • 1,311
7 votes
18 answers
2k 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, ...
Soham Chowdhury's user avatar
6 votes
3 answers
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, ...
Edward Brey's user avatar
23 votes
4 answers
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 ...
user avatar
12 votes
6 answers
896 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 ...
cardboard_box's user avatar
4 votes
2 answers
560 views

List ALL prime-factorized natural numbers in ANY order [closed]

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 ...
Petr's user avatar
  • 4,360
8 votes
3 answers
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 ...
Petr's user avatar
  • 4,360
19 votes
19 answers
4k 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 ...
Polynomial's user avatar
  • 4,506
16 votes
40 answers
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 ...
leonardo's user avatar
  • 341
7 votes
16 answers
850 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, ...
leonardo's user avatar
  • 341
17 votes
9 answers
1k 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-...
mellamokb's user avatar
  • 6,083
24 votes
26 answers
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 ...
FUZxxl's user avatar
  • 10.1k
9 votes
4 answers
906 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 ...
Eelvex's user avatar
  • 5,502
18 votes
9 answers
894 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=...
st0le's user avatar
  • 2,218
27 votes
19 answers
5k 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 ...
fR0DDY's user avatar
  • 4,577
13 votes
5 answers
655 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 ...
fR0DDY's user avatar
  • 4,577
9 votes
15 answers
827 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 ...
fR0DDY's user avatar
  • 4,577
9 votes
10 answers
667 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\$ ...
fR0DDY's user avatar
  • 4,577
19 votes
12 answers
892 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 ...
Keith Randall's user avatar
26 votes
14 answers
5k views

Hamming numbers

Hamming numbers are numbers which evenly divide a power of 60. Equivalently, their prime factors are all \$ \le 5 \$. Given a positive integer, print that many Hamming numbers, in order. Rules: Input ...
grokus's user avatar
  • 1,297

1
6 7 8 9
10