Hello,
I'm looking for ideas/code (preferably C#, but other languages work too) to create Ulam's Spiral infinitely large (limited by length of time the program is running, or until stopped).
Now the numbers are all primes so the code for those is rather irrelevant. The interesting part is how to code the arrangement in the evergrowi...
I wrote the following program to prime factorize a number:
import math
def prime_factorize(x,li=[]):
until = int(math.sqrt(x))+1
for i in xrange(2,until):
if not x%i:
li.append(i)
break
else: #This else belongs to for
li.append(x)
print li #First print state...
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 of the software I've found that can do this in JavaScript seems to use the JavaScript Bi...
I am currently working with a sparc computer and I am trying to know if a number is prime or not.
here is a part of the code :
mov 0,%y
mov 3, %l1
nop
nop
nop
sdiv %l1,2,%l3
rd %y, %l6
cmp %l6, 0
So basicaly what we have here is 3/2. So there should be a reminder of 1. This r...
I'm trying to construct a program that finds prime numbers between zero and the number input (a really long number); but the program isn't returning an output like I'm expecting it to:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication16
{
class Program
{
...
I was wondering if someone here have a good implementation of the Sieve of Atkin that they would like to share.
I am trying to implement it, but can't quite wrap my head around it. Here is what I have so far.
public class Atkin : IEnumerable<ulong>
{
private readonly List<ulong> primes;
private readonly ulong limit;
publi...
I don't know if this is possible or not, but I just gotta ask. My mathematical and algorithmic skills are kind of failing me here :P
The thing is I now have this class that generates prime numbers up to a certain limit:
public class Atkin : IEnumerable<ulong>
{
private readonly List<ulong> primes;
private readonly ulong limit;
...
Is there any nice algorithm to find the nearest prime number to a given real number? I only need to search within the first 100 primes or so.
At present, I've a bunch of prime numbers stored in an array and I'm checking the difference one number at a time (O(n)?).
...
Hi All,
I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number.
For eg.: User...
Where can I find a prime number generator in C?
...
How do I quickly generate a random prime number, that is for sure 1024 bit long?
...
I came across this (really) simple program a while ago. It just outputs the first x primes. I'm embarrassed to ask, is there any way to make it more "pythonic" ie condense it while making it (more) readable? Switching functions is fine; I'm only interested in readability.
Thanks
from math import sqrt
def isprime(n):
if n ==2:
...
Assume the availability of a function is_prime. Assume a variable n has been associated with a positive integer. Write the statements needed to compute the sum of the first n prime numbers. The sum should be associated with the variable total.
Note: is_prime takes an integer as a parameter and returns True if and only if that integer...
So after pulling my hair out for 30 minutes, I have decided to come to SO for some help on Project Euler #10:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Now, I don't want to know how to do the problem - that's easy - and especially not the answer. I would like to kno...
I a m trying to generate a random prime number of type BigInteger, that is between an min and max value which I supply.
I am aware of the BigInteger.probablePrime(int bitlength, random), but I am not sure how or even if the bitlength translates into a max/min value of the outputted prime.
Thanks,
Steven1350
...
Possible Duplicate:
Efficient storage of prime numbers
Just an example of what I am looking for: I could represent every odd number with a bit e.g. for the given range of numbers (1, 10], starts at 3:
1110
The following dictionary can be squeezed more right? I could eleminate multiples of five with some work, but numbers that...
Eclipse 3.5 has a very nice feature to generate Java hashCode() functions. It would generate for example (slightly shortened:)
class HashTest {
int i;
int j;
public int hashCode() {
final int prime = 31;
int result = prime + i;
result = prime * result + j;
return result;
}
}
(If ...
Hi all,
I'm very new to Erlang and I'm currently reading Joe Armstrong's book, chapter 'concurrent programming'. I'm trying to run a list of processes to calculate if a number is a prime (naive method). But my code runs as if there was no processes. Both methods have the same duration. Where am I wrong ?
shell.erl:
c(prime).
%a list ...
I am trying to write a program to find the largest prime factor of a very large number, and have tried several methods with varying success. All of the ones I have found so far have been unbelievably slow. I had a thought, and am wondering if this is a valid approach:
long number = input;
while(notPrime(number))
{
number = number /...
This problem struck me as a bit odd. I'm curious how you could represent a list of prime numbers in a database. I do not know of a single datatype that would be able to acuratly and consistently store a large amount of prime numbers. My concern is that when the prime numbers are starting to contain 1000s of digits, that it might be a bit...