Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"Were there no women, men might live like gods." -- Thomas Dekker


devel / comp.theory / A problem about prime number

SubjectAuthor
* A problem about prime numberwij
+- Re: A problem about prime numberBen Bacarisse
`- Re: A problem about prime numberimmibis

1
A problem about prime number

<96fb52707d9b745c1d3e9f916c194ca16b728e27.camel@gmail.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=53552&group=comp.theory#53552

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!news.samoylyk.net!nyheter.lysator.liu.se!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wyniijj5@gmail.com (wij)
Newsgroups: comp.theory
Subject: A problem about prime number
Date: Sat, 17 Feb 2024 05:12:00 +0800
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <96fb52707d9b745c1d3e9f916c194ca16b728e27.camel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="0a77e9e8b378efa188c1ddac01a3668e";
logging-data="25608"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7DWP5SOPjX1WUdudG39Zx"
User-Agent: Evolution 3.50.2 (3.50.2-1.fc39)
Cancel-Lock: sha1:ukA/K7KG/y8GCAFic+g3eWoij7c=
 by: wij - Fri, 16 Feb 2024 21:12 UTC

I just wrote a short c++ program to test prime numbers. The programĀ 
indicates that if n (n<=2^32) is a prime then n%30 is also a prime !!!
I think I should have made some mistake but have no idea what. Can
anybody find some thing for me, thanks.

//-------------------------------------------
#include <Wy.stdio.h>
#include "PrimeTab.h"

using namespace Wy;

void ck() {
size_t cnt;
PrimeTab ptab(1LL<<32);
cnt=0;
for(size_t n=0; n<ptab.max_num(); ++n) {
if(ptab.is_prime(n)) {
++cnt;
PrimeTab::NumType n2= n%30;
if(ptab.is_prime(n2)==false) {
cout << n << ' ' << n2 << WY_ENDL;
}
}
}
cout << "cnt=" << cnt << WY_ENDL;
};

int main() {
//...
ck();
return 0;
};

Re: A problem about prime number

<875xyojds9.fsf@bsb.me.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=53556&group=comp.theory#53556

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!news.samoylyk.net!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.theory
Subject: Re: A problem about prime number
Date: Fri, 16 Feb 2024 21:32:38 +0000
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <875xyojds9.fsf@bsb.me.uk>
References: <96fb52707d9b745c1d3e9f916c194ca16b728e27.camel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="3b3f5f8035cfa27c512afe92b62a0432";
logging-data="49340"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18p1yjdADa6KMlJikZzcs4F4SLyXaOd4Bk="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:YJ6KlWgQ2rYojGcIVUimQ7/1aAk=
sha1:vTN1nz3C1DLe10awlDt/NmPu6IE=
X-BSB-Auth: 1.9786b7b855109ae088d8.20240216213238GMT.875xyojds9.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 16 Feb 2024 21:32 UTC

wij <wyniijj5@gmail.com> writes:

> I just wrote a short c++ program to test prime numbers. The programĀ 
> indicates that if n (n<=2^32) is a prime then n%30 is also a prime !!!
> I think I should have made some mistake but have no idea what. Can
> anybody find some thing for me, thanks.

We're missing the key part of the program.

> //-------------------------------------------
> #include <Wy.stdio.h>
> #include "PrimeTab.h"

Without knowing what's in here (and any other files linked to the code
you show), how can we tell?

> using namespace Wy;
>
> void ck() {
> size_t cnt;
> PrimeTab ptab(1LL<<32);
> cnt=0;
> for(size_t n=0; n<ptab.max_num(); ++n) {
> if(ptab.is_prime(n)) {
> ++cnt;
> PrimeTab::NumType n2= n%30;
> if(ptab.is_prime(n2)==false) {
> cout << n << ' ' << n2 << WY_ENDL;
> }
> }
> }
> cout << "cnt=" << cnt << WY_ENDL;
> };

See below.

> int main() {
> //...
> ck();
> return 0;
> };

It's odd to put ; after a function definition. It's a syntax error in C
but C++ does allow it. None the less, odd.

--
Ben.

Re: A problem about prime number

<uqolj9$1n6g$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=53558&group=comp.theory#53558

  copy link   Newsgroups: comp.theory
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: news@immibis.com (immibis)
Newsgroups: comp.theory
Subject: Re: A problem about prime number
Date: Fri, 16 Feb 2024 22:54:47 +0100
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <uqolj9$1n6g$1@dont-email.me>
References: <96fb52707d9b745c1d3e9f916c194ca16b728e27.camel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Feb 2024 21:54:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a72c6e42d4145dab8c6e694476930390";
logging-data="56528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190qWDXinGNinbuJ/O+Bslg"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Tn5+jzN5QDabqxms5Kb+qaGIio0=
Content-Language: en-US
In-Reply-To: <96fb52707d9b745c1d3e9f916c194ca16b728e27.camel@gmail.com>
 by: immibis - Fri, 16 Feb 2024 21:54 UTC

On 16/02/24 22:12, wij wrote:
> I just wrote a short c++ program to test prime numbers. The program
> indicates that if n (n<=2^32) is a prime then n%30 is also a prime !!!
> I think I should have made some mistake but have no idea what. Can
> anybody find some thing for me, thanks.
>
> //-------------------------------------------
> #include <Wy.stdio.h>
> #include "PrimeTab.h"
>
> using namespace Wy;
>
> void ck() {
> size_t cnt;
> PrimeTab ptab(1LL<<32);
> cnt=0;
> for(size_t n=0; n<ptab.max_num(); ++n) {
> if(ptab.is_prime(n)) {
> ++cnt;
> PrimeTab::NumType n2= n%30;
> if(ptab.is_prime(n2)==false) {
> cout << n << ' ' << n2 << WY_ENDL;
> }
> }
> }
> cout << "cnt=" << cnt << WY_ENDL;
> };
>
> int main() {
> //...
> ck();
> return 0;
> };
>
>

If you multiply consecutive prime numbers starting from 2, to get a
number like 2x3x5==30, and then look at prime numbers modulo 30 you see
there are only certain possible values.

Since 30 is a multiple of 2, n%2 == (n-30*k)%2.
By choosing k so that (n-30*k)==n%30 we know n%2==(n%30)%2.
Ditto for 3 and 5.
So if n isn't divisible by 2 or 3 or 5, n%30 still isn't divisible by 2
or 3 or 5.

Here are the numbers less than 30 that aren't divisible by 2, 3 or 5:
1, 7, 11, 13, 17, 19, 23, 29

As you can see they are all prime! ... except for 1. And some prime
numbers mod 30 are 1, such as 31. It's only always prime if you count 1
as prime.

That's because all the numbers less than 30 are either divisible by 2, 3
or 5, or they are prime. The first non-prime number that isn't divisible
by one of those is 49, which is 7x7.

Why only 30? What happens if we try a different modulus? Instead of mod
2x3x5 we can try mod 2x3 or mod 2x3x5x7.

If you take away 5 and try mod 6 (2x3) it works: all prime numbers mod 6
are either 1, or 5 (which is prime).

If you also take away 3 and try mod 2 it almost works, since 2%2==0. But
that's the only exception - all other primes mod 2 are 1.

If you try adding more primes and try mod 210 (2x3x5x7) it doesn't work.
It still works that all the mods aren't divisible by 2, 3, 5 or 7 (and
that will keep working as you add more primes - any primes, not just
consecutive ones) but it doesn't work that those are the only prime
numbers. 121 (11x11) is a number less than 210 which isn't divisible by
2, 3, 5 or 7.
541 is a prime number and 541%210==121.

2x3x5==30 is the only sweet spot where all the numbers less than 30 that
aren't divisible by 2, 3, or 5 are prime (or 1).

What if we skip over some, e.g. do 3x5 instead of 2x3x5? Well then the
numbers that aren't divisible by them aren't all prime, either. E.g. 14
isn't divisible by 3 or 5, but it's less than 15 and not prime. 29 is a
prime and 29%15==14.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor