I recently read about a faster implementation of Segmented Sieve of Eratosthenes for really big numbers.  Following is an implementation of the same:  function sieve(low, high) {      var primeArray = [], ll = Math.sqrt(low), output = [];      for (v...
My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime number of 2048 bits, and g may have up to 2048 bits.  Most...
Input: 13195 Expected Result: 29 (largest prime factor of input) Actual Result: 2639 (largest factor of input, but not a prime number)  I didn't bother with even numbers because the largest prime will either be 2 or some odd prime multiplied by 2...
I have been trying to write Sieve of Eratosthenes algorithm in JavaScript. Basically I just literally followed the steps below:   Create a list of consecutive integers from 2 to (n-1) Let first prime number p equal 2 Starting from p, count up in incr...
I am trying to determine whether the value in a text box is prime or not using jQuery.  Here is what I've tried so far, but it's not working:    $("#textbx").keyup(function(){  if ($("#textbx").val().length > 0) { 	  $("...
And how can I correct them to work? I am trying to optimize my sieve per previous suggestions, but in both instances the code breaks:  Incrementing j = j + ( i * 2) will break the code.  Obviously I'm missing some concept on optimizations as well...
I have an input field to take a maximum number and find all smaller prime numbers.  It should return to an array and display the array with an alert.  Except I'm getting blank every time.  HTML:  <p>Please enter the maximum number you'd...
So I wanted to write a function that returns the sum of all prime numbers up to and including a provided number.   I have written this, which works:    function sumPrimes(num) {   const arr = Array.from({length: num+1}, (v, k) => k).slice(2);   re...
This question already has answers here:...
I'm trying to sum all primes up to a number.  First I removed all evens and pushed the rest to an odd-only array.  Then i'm going over the array and splicing all the numbers that divide by other numbers but 1 and themselves, and replacing the...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.