Linked Questions
49 questions linked to/from Modular arithmetics and NTT (finite field DFT) optimizations
13 votes
8 answers
883 views
Get the last 1000 digits of 5^1234566789893943
I saw the following interview question on some online forum. What is a good solution for this? Get the last 1000 digits of 5^1234566789893943
20 votes
3 answers
7k views
Fast bignum square computation
To speed up my bignum divisons I need to speed up operation y = x^2 for bigints which are represented as dynamic arrays of unsigned DWORDs. To be clear: DWORD x[n+1] = { LSW, ......, MSW }; where n+1 ...
11 votes
2 answers
8k views
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 ...
6 votes
1 answer
14k views
How to compute Discrete Fourier Transform?
I've been trying to find some places to help me better understand DFT and how to compute it but to no avail. So I need help understanding DFT and it's computation of complex numbers. Basically, I'm ...
6 votes
3 answers
12k views
Multiplication of very large numbers using character strings
I'm trying to write a C program which performs multiplication of two numbers without directly using the multiplication operator, and it should take into account numbers which are sufficiently large so ...
9 votes
2 answers
2k views
Why do BigInteger implementations use sign-magnitude instead of two's complement?
Arbitary-precision signed integers are almost always implemented using a sign-magnitude representation: (Java) BigInteger in OpenJDK (Python) Bigint implementation of the Python built-in int type in ...
4 votes
1 answer
7k views
BigInteger numbers implementation and performance
I have written a BigInteger class in C++ that should be able to do operations on all numbers with any size. Currently I am trying to achieve a very fast multiplication method by comparing the existing ...
17 votes
2 answers
1k views
Alternate way to compute product of pairwise sums mod 10^9+7 faster than O(N^2)
Given an array A of integers of size N, I want to compute This was a problem in a past inter-college programming competition. We had to write a program that would solve up to 5 instance of this ...
3 votes
3 answers
2k views
Translation from Complex-FFT to Finite-Field-FFT
Good afternoon! I am trying to develop an NTT algorithm based on the naive recursive FFT implementation I already have. Consider the following code (coefficients' length, let it be m, is an exact ...
2 votes
3 answers
3k views
Taking Modulo of Double NUmber
I have given two number a and b.I have to Calculate (a^b)%1000000007.How Can i calculate for floating point numbers. Ex: a= 7.654 and b=10000 Here is my Code will % work : public static double ...
4 votes
3 answers
1k views
Calculating very large power
I want to calculate for very large numbers like n = 10^15. Somehow I can't, because of OverflowError. xd = lambda n : ((((5+ sqrt(17)) * ((3 + sqrt(17)) ** n)) - ((5-sqrt(17))* ((3 - sqrt(17)) ** n)))/...
-3 votes
1 answer
3k views
Arithmetic with base 256 number system
I am working on a project right now where I need to perform calculations for numbers with base 256. I am reading bytes of a file and storing it in an array of uint8_t (a.k.a unsigned char or BYTE). ...
1 vote
3 answers
4k views
Implementing (A ^ B) % C i.e, pow(A, B) % C
I am given with three integers A, B and C. I need to implement a program to perform the operation A^B modulus C. I without thinking much, wrote the following code:- public int Mod(int A, int B, int C) ...
2 votes
2 answers
3k views
Modulus of Product of two integers
I have to find c, c = (a*b) mod m a,b,c,m are 32-bit integers. But (a*b) can be more than 32 bits. I am trying to figure out a way to compute c, without using long or any data type > 32 bit. Any ...
9 votes
1 answer
2k views
Implementing FFT over finite fields
I would like to implement multiplication of polynomials using NTT. I followed Number-theoretic transform (integer DFT) and it seems to work. Now I would like to implement multiplication of ...