Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Nested loops

by danaj (Friar)
on Sep 16, 2015 at 02:58 UTC ( [id://1142158]=note: print w/replies, xml ) Need Help??


in reply to Nested loops

use ntheory ":all"; use feature "say"; say scalar(grep { gcd($_,13*17*19)==1 } 1..2310);

Seems much easier than all the looping or recursion. The gcd will return 1 if the two inputs have no common factors -- if it isn't divisible by 13, 17, or 19 in this example.

Replies are listed 'Best First'.
Re^2: Nested loops
by robert44444uk (Acolyte) on Sep 20, 2015 at 18:56 UTC

    Hi danaj, fancy seeing you here! Thank you for this, will give it a work through when I get some time. You know why I am trying to do this program from Mersenneforum and it will need to be pretty efficient as I want to add more primes to get to an under-researched prime gap formula. Hard to beat your 1 liner, I think.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1142158]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-24 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found