Multiply two polynomials over the Mersenne field:
Let and be polynomials of degree with coefficients in :
Compute their product modulo :
The result is a coefficient vector of length :
d_input1
, d_input2
of length , with values in .d_output
of length with coefficients of modulo .For small :
Their product is:
So:
A naive implementation:
const uint32_t P = 2147483647u;
static __host__ __device__ inline uint32_t add_mod(uint32_t a, uint32_t b) {
uint64_t s = (uint64_t)a + b;
return (uint32_t)(s % P);
}
static __host__ __device__ inline uint32_t mul_mod(uint32_t a, uint32_t b) {
uint64_t prod = (uint64_t)a * b;
return (uint32_t)(prod % P);
}
for (size_t i = 0; i < n; ++i) {
for (size_t j = 0; j < n; ++j) {
d_output[i + j] = add_mod(d_output[i + j], mul_mod(d_input1[i], d_input2[j]));
}
}
GPU Type
Language
Data Type
Loading editor...
CUDA C++ environment
Sample Run Results
Hit "Run" to test your code with sample inputs
For the best coding experience, please switch to a desktop device to write and submit your solution.