Questions tagged [number-theory]

Number theory is that branch of mathematics that investigates the properties of numbers, typically whole numbers.

Number theory is that branch of mathematics that investigates the properties of numbers, typically whole numbers. Applications include cryptography, error correcting codes, checksums, and programming, since many tasks in programming are made much simpler using modular arithmetic. Key concepts/topics: modular arithmetic, unique factorisation theorem, prime numbers, congruences.

Advanced number theory is better treated on:

419 questions
7
votes
3 answers

Why did I get this [1, 2, 4, 8, 16, 1, 16, 8, 4, 2, 1]?

Through much trial and error I found the following lines of python code, for N in range(2**1,2**3): print [(2**n % (3*2**(2*N - n))) % (2**N-1) for n in range(2*N+1)] which produce the following output, [1, 2, 1, 2, 1] [1, 2, 4, 1, 4, 2, 1] [1,…
lafras
  • 7,025
  • 4
  • 26
  • 28
7
votes
4 answers

How to find Consecutive Numbers Among multiple Arrays?

I right away give an example, now suppose I have 3 arrays a,b,c such as a = c(3,5) b = c(6,1,8,7) c = c(4,2,9) I must be able to extract consecutive triplets among them i,e., c(1,2,3),c(4,5,6) But this was just an example, I would be having a…
7
votes
2 answers

Extremely fast method for modular exponentiation with modulus and exponent of several million digits

As a hobby project I'm taking a crack at finding really large prime numbers. The primality tests for this contain modular exponentiation calculations, i.e. a^e mod n. Let's call this the modpow operation to keep the explanation simple. I am wanting…
7
votes
1 answer

How to generate all multiplicative partitions of a number if I have a list of primes/exponents?

For instance, the number 24 has prime factorization 2^3*3^1, and can be written in the following ways 1*24 2*12 2*2*6 2*3*4 2*2*2*3 3*8 4*6 I may have missed one but you get the idea. I tried looking into the other thread How to find multiplicative…
John Smith
  • 9,380
  • 16
  • 43
  • 49
6
votes
4 answers

Speed up calculation of partitions in Haskell

I'm trying to solve Euler problem 78, which basically asks for the first number where the partition function p(n) is divisible by 1000000. I use Euler's recursive fomula based on pentagonal numbers (calculated here in pents together with the proper…
Landei
  • 52,346
  • 12
  • 89
  • 188
6
votes
5 answers

Generate very very large random numbers

How would you generate a very very large random number? I am thinking on the order of 2^10^9 (one billion bits). Any programming language -- I assume the solution would translate to other languages. I would like a uniform distribution on [1,N]. My…
usul
  • 754
  • 5
  • 15
6
votes
3 answers

how to represent a number as a sum of 4 primes?

Here is the problem (Summation of Four Primes) states that : The input contains one integer number N (N<=10000000) in every line. This is the number you will have to express as a summation of four primes Sample Input: 24 36 46 Sample Output: …
user467871
6
votes
3 answers

What is the time complexity of this algorithm

Write a program that takes an integer and prints out all ways to multiply smaller integers that equal the original number, without repeating sets of factors. In other words, if your output contains 4 * 3, you should not print out 3 * 4 again as…
user12331
  • 533
  • 4
  • 17
6
votes
3 answers

Sieve of Eratosthenes in Haskell

I'm solving some classic problems in Haskell to develop my functional skills and I have a problem to implement an optimization suggested at this "Programming Praxis" site: I have three solutions to this problem and the third one is too slow…
6
votes
1 answer

Number which can be written as sum of two Squares

From the math principle: A number N is expressible as a sum of 2 squares if and only if in the prime factorization of N, every prime of the form (4k+3) occurs an even number of times! What I did is pre-calculated all the 4k+3 numbers and checking…
Uma Kanth
  • 5,614
  • 2
  • 16
  • 40
6
votes
3 answers

Riemann Zeta Function in Java - Infinite Recursion with Functional Form

Note: Updated on 06/17/2015. Of course this is possible. See the solution below. Even if anyone copies and pastes this code, you still have a lot of cleanup to do. Also note that you will have problems inside the critical strip from Re(s) = 0 to…
Axion004
  • 873
  • 1
  • 8
  • 33
6
votes
3 answers

Product of Prime factors of a number

Given a number X , what would be the most efficient way to calculate the product of the prime factors of that number? Is there a way to do this without actual factorisation ? Note-The product of prime factors is needed (all to the power unity).
LTim
  • 463
  • 1
  • 4
  • 15
6
votes
4 answers

How to check if the number can be represented prime power (nth root is prime or not)

I am trying this problem for a while but getting wrong answer again and again. number can be very large <=2^2014. 22086. Prime Power Test Explanation about my algorithm: For a Given number I am checking if the number can be represented as form of…
Lakshman
  • 374
  • 3
  • 12
6
votes
2 answers

Efficiently compute the modulo of the sum of two numbers

I have three N-bit numbers, A, B, and C. I cannot easily calculate (A + B) % C but I can easily calculate A % C and B % C. If the modulo operation is unsigned and I know ahead of time that A + B does not wrap around N bits then I can instead…
6
votes
2 answers

How does addition work in Computers?

I was watching a video on computer architecture and a question came to my mind. How does addition and basic operations work on computers? I mean, i know that 2+2 = 4 but i don't know why? i just know that if i add 2 apples to another 2 then i see 4,…
HardCodeStuds
  • 387
  • 1
  • 8
  • 27
1 2
3
27 28