## Other

drummers-lowrise

Message boards : General discussion : Get prime from concatenating first n numbers

Author Message
Message 152676 - Posted: 15 Dec 2021 | 16:24:21 UTC

Numberphile's newest video is The Most Wanted Prime Number, featuring N. J. A. Sloane from the OEIS.

They want to find a prime number by concatenating the (decimal) representations of 1, 2, 3, ..., n. You can search in PARI/GP like this:

If you change the first part to other bases, like b=12, you find examples.

/JeppeSN

Message 152677 - Posted: 15 Dec 2021 | 16:36:30 UTC

I see that:

82 81 80 79 78 ... 11 10 9 8 7 6 5 4 3 2 1

is a prime number.

/JeppeSN

Message 152678 - Posted: 15 Dec 2021 | 17:09:41 UTC - in response to Message 152676.

Numberphile's newest video is The Most Wanted Prime Number, featuring N. J. A. Sloane from the OEIS.

They want to find a prime number by concatenating the (decimal) representations of 1, 2, 3, ..., n. You can search in PARI/GP like this:

If you change the first part to other bases, like b=12, you find examples.

/JeppeSN

Nice !
____________ "Accidit in puncto, quod non contingit in anno."
Something that does not occur in a year may, perchance, happen in a moment.

Message 152680 - Posted: 15 Dec 2021 | 17:36:02 UTC

Turns out 82 is followed by 37765; see A176024. Also see Mersenneforum thread Smarandache prime(s). /JeppeSN

Message 152773 - Posted: 22 Dec 2021 | 18:03:44 UTC - in response to Message 152680.

Jeppe, I tried the same, but my code for creating the number is a bit more complicated... :)

m=2000;p=0;k=0;for (i=1,m,k+=ceil(log(i)/log(10));p+=i*10^k;if(ispseudoprime(p),print("Prime: ",p)))

And the other suggested format of increasing and then decreasing values like 12345678910987654321:

updown(r,s) = {
b=s;
for(a=r,s-1,
p=0;k=0;for (i=a,b,p+=i*10^k;k+=(floor(log(i)/log(10))+1));
q=0;k=0;for (i=1,b-a,j=b-i;q+=j*10^k;k+=(floor(log(j)/log(10))+1));
p+=q*10^(floor(log(p)/log(10))+1);
\\ print(p);
if(ispseudoprime(p),print("yay: ",p," is prime!"))
)
}

And to run it: for(i=2,100,updown(1,i)) tests all number with 2 ... 100 in the middle and beginning at 1 to the middle value. Such as 121, 232, 12321, 343, 23432, 1234321, ...

Your slim code could be used there as well though. I got to understand what's going on there at first though.
____________
1281979 * 2^485014 + 1 is prime ... no further hits up to: n = 5,700,000

Message 152775 - Posted: 22 Dec 2021 | 19:32:45 UTC

Where you say ceil(log(i)/log(10)), you can use 1+logint(i, 10) instead. Otherwise, it is more or less the same.

The good thing about logint (integer logarithm) is, it does not go through floating-point. It simply finds the "integer logarithm" of i, to base 10. You do not have to care about the value of the default realprecision.

Oh, and then I (ab)use the short-circuiting behavior of &&. So instead of:

if(b, something())

you can say:

b && something()

/JeppeSN

Message 152778 - Posted: 23 Dec 2021 | 14:29:38 UTC - in response to Message 152775.

So the output of logint(a,b) is always identical to floor(log_b(a)) it just saves computing time by not going through the actual calculation of the log?

Interesting take on the & instead of if. Now I realized I actually used that a couple of times before just not in such simple constructs but only within an if clause to indicate progress by throwing an &!(print(...)) in there. Btw, is it convention that print(a) returns 0 upon successfully printing?
____________
1281979 * 2^485014 + 1 is prime ... no further hits up to: n = 5,700,000

Message 152781 - Posted: 23 Dec 2021 | 19:31:34 UTC - in response to Message 152778.

Btw, is it convention that print(a) returns 0 upon successfully printing?

Yes, in PARI/GP, a "procedure" is a function which does not return anything (or returns the special void object, according to the user's manual). But this void thing will become a zero if you pick it up. For example:

print("hello") -print("hello") a=print("hello")

In the first example, the return value is void and is suppressed (not seen). In the second example, we force the use of void by negating it, and it becomes zero. This is like the 1&&print("hello") you ask for. In the third example above, again we get zero, this time stored in the variable a.

If in your home-made function, it reaches a return() with no argument, it behaves the same. It is allowed to omit the parenthesis.

/JeppeSN

Message boards : General discussion : Get prime from concatenating first n numbers