boolean isPrime=true;
for(int k = 2 ; k < number ; k++)
{
if ( number/k == 0)
isPrime=false;
}
I know that :P
But I need to write a formula so Java can know if the number is prime or not
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )
I know that :P
But I need to write a formula so Java can know if the number is prime or not
EDIT: never mind. I got itCode: [Select]boolean isPrime=true;
for(int k = 2 ; k < number ; k++)
{
if ( number/k == 0)
isPrime=false;
}
boolean isPrime=true;
for(int k = 2 ; k < number ; k++)
{
if (number==2 || number/k == 0)
isPrime=false;
}
oops O_oCode: [Select]boolean isPrime=true;
for(int k = 2 ; k < number ; k++)
{
if (number==2 || number/k == 0)
isPrime=false;
}
EDIT: Aww
boolean isPrime=true;
for(int k = 2 ; k < number ; k++)
if ( number/k == 0)
isPrime=false;
It has been proven, by the way, that there is no largest prime number 8)It's been proven in more than one way, too.
I once wrote a TI Basic program to find prime numbers that used this pattern I found among the spacing between primes. I think it was able to count out about 1000 primes in rhe first hour and could also save its state at any time so you wouldn't have to start over.Very nice. I don't remember where it starts, but there is a point where primes are basically spaced 2, then 4 apart. So, for example, starting with 1. 1+4=5. 5+2=7. 7+4=11. 11+2=13. 13+4=17, etc.
I have a nice theory working too.It actually does matter, because even if you had all the primes from 0 to n-1, it would still be just as difficult to search through them all. So, no, it doesn't help at all with RSA.
It'll take a bit of space, so....Spoiler For stuff you care about:
Edited for better readability
Edit: Also, I find it worth noting that since the math involved in this is fairly simple, and not based on the size of the number, it is practical for use on RSA cracking :P
Arrange your numbers in a matrix. The width determines the numbers you can eliminate.
Here's the basic concept. The width is a multiple of several prime numbers. If you multiply 3,5,and 7
together you get 105. In the 105 columns, you can eliminate every 3rd starting at 3, every 5th starting
at 5, and every 7th starting at 7. You don't need to put in two, since you can simply eliminate every
other going down each column (-210 instead of -105)
Example using 3*5 (15)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
1 2 4 7 8 11 13 14
16 17 19 22 23 26 28 29
31 32 34 37 38 41 43 44
46 47 49 52 53 56 58 59
The more primes you multiply in (nonprimes are useless, eliminate no more rows) the more you can eliminate! yay!
Now for checkerboarding for multiples of 2:
1 7 11 13
17 19 23 29
31 37 41 43
47 49 53 59
True, you eliminate two, but who cares? You don't lose any primes.
By the way, doing this exactly this way with 105 (0-104) give you 31.428% remaining, whereas 3 gives 33.333% It's exponentially less effective, but still waaay better than just -2.
I put it in a spoiler so It wouldn't take up the whole page, in the code for the monospace for laying out the matrices.
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
There is nothing that says it can or cannot be true. It would kinda fit into the category of P=NP, though. e.g., you can prove S times T equals a number, but finding S and T from that number would be a lot harder.Yep, I think from what I read it falls on that category.
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.
There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem
For RSA we are talking of numbers with hundreds of decimal digits.Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.
There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem
Wait a minute... I can code a program that gets all prime numbers in a second.
For RSA we are talking of numbers with hundreds of decimal digits.Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.
There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem
Wait a minute... I can code a program that gets all prime numbers in a second.
The number of decimal digits representation of the integer. It is true that it is always integer in this sort of things. Don't confuse "decimal type" with its "decimal representation".For RSA we are talking of numbers with hundreds of decimal digits.Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.
There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem
Wait a minute... I can code a program that gets all prime numbers in a second.
decimal! I thought only integers would take part of such function.