Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.9K Views
|
8 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Catch throw with no results

Can anyone tell me if the program lines are correct ? It doe not give me any output and suddenly stops

n=69473167820511765242830133883162231196373893172462572947321681009276855429531868770882474054742274999418781196191128350605290638907281085633288937673680524199820066895936872314770237447995716771439959238004273486653770489519884087184561255933086729316005893883052796589968722075656357507968378869005241089165689837538775946470654446499501966076614890157622775988094202464078929288907735084091176712819439586018201262584675330599303231799651328074634544385044419476755076985251636084219268328080088251662043698866454523084731639802544765817015037852583580045461950139773968906062830312323507628556726568436388771648582054725350555439952871014106950029398605002226628662285437033779318551536747294374952255496472680780665826457366896250220249866954099419856397786258180576705276869616498812031948075619511682529816958383878485379938346995226313984712037892411186524390370830098196489452622389323720195586168765517245297601070346396828054779915463530671108671936053175605957994436181065402719501539141
sq=Table[j,{j,10000}]
b=Select[sq,PrimeQ,(1000)]
n1=(n^2-1)+b
Catch[Do[If[PrimeQ[n1],Throw[n1]],1]]
8 Replies

Here something without Do, giving several (here two) answers, but running several minutes. (Use your n given above)

sq = Table[j, {j, 10000}];
b = Select[sq, PrimeQ, 1000];
n1 = (n^2 - 1);
b1 = Transpose[{Range[Length[b]], b}];
Select[b1, PrimeQ[#[[2]] + n1] &]
POSTED BY: Hans Dolhaine

Perhaps you meant this ( but it takes quite a time, at least on my machine and version (Mathematica 7))

n = 694731678205117652428301338831622311963738931724625729473216810092\
7685542953186877088247405474227499941878119619112835060529063890728108\
5633288937673680524199820066895936872314770237447995716771439959238004\
2734866537704895198840871845612559330867293160058938830527965899687220\
7565635750796837886900524108916568983753877594647065444649950196607661\
4890157622775988094202464078929288907735084091176712819439586018201262\
5846753305993032317996513280746345443850444194767550769852516360842192\
6832808008825166204369886645452308473163980254476581701503785258358004\
5461950139773968906062830312323507628556726568436388771648582054725350\
5554399528710141069500293986050022266286622854370337793185515367472943\
7495225549647268078066582645736689625022024986695409941985639778625818\
0576705276869616498812031948075619511682529816958383878485379938346995\
2263139847120378924111865243903708300981964894526223893237201955861687\
6551724529760107034639682805477991546353067110867193605317560595799443\
6181065402719501539141;

sq = Table[j, {j, 10000}];
b = Select[sq, PrimeQ, 1000];
n1 = (n^2 - 1);
Catch[
 Do[
  If[PrimeQ[n1 + b[[i]]], Throw[b[[i]]]],
  {i, 1, Length[b]}
  ]]
POSTED BY: Hans Dolhaine

Hello, it is by no means clear what you want to do.

Your do-loop doesn't have an iterator and can't work. Then: b should be an array which is added to n^2 - 1, that means to any element of b is added this expression, but what is n?

POSTED BY: Hans Dolhaine
Posted 5 years ago

Hello, it is by no means clear what you want to do.

POSTED BY: Brad war

Thanks once again Hans, you are incredible!!!

If it is correct then the number caught is a prime ... it is what I want to prove that the square of a prime number -1 + a certain prime gives a prime number, so the reverse is also true and it serves as a way, probably faster to check if a number is a prime upon the use of a table of other primes, but you surely helped me a lot....Thank you so much God bless you.

But now I am running in to another problem if I pick the result of the calculation it is giving unequal length problem which does not happen in the first calculation... I want to loop this until it hits over the largest known prime, but I think it is too ambitious..

I got what I wanted by a different manner, but I still would like to learn how to loop.

n=69473167820511765242830133883162231196373893172462572947321681009276855429531868770882474054742274999418781196191128350605290638907281085633288937673680524199820066895936872314770237447995716771439959238004273486653770489519884087184561255933086729316005893883052796589968722075656357507968378869005241089165689837538775946470654446499501966076614890157622775988094202464078929288907735084091176712819439586018201262584675330599303231799651328074634544385044419476755076985251636084219268328080088251662043698866454523084731639802544765817015037852583580045461950139773968906062830312323507628556726568436388771648582054725350555439952871014106950029398605002226628662285437033779318551536747294374952255496472680780665826457366896250220249866954099419856397786258180576705276869616498812031948075619511682529816958383878485379938346995226313984712037892411186524390370830098196489452622389323720195586168765517245297601070346396828054779915463530671108671936053175605957994436181065402719501539141
sq=Table[j,{j,10000}]
b=Select[sq,PrimeQ,(1000)]
n2=(n^2-1)-(b)
n1=(n^2-1)+b

b1=Select[n1,PrimeQ,(10)]

Hi Hans! n is the large prime number on the first line. I just want to add a prime number to the square of n -1 and throw when the result is a prime number. On wolfram documentation it says the last digit 1 after the Throw[1]], is the number of times i want to do the loop. Could you tell me how to make the loop right?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard