Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Nested loops

by danaj (Friar)
on Sep 16, 2015 at 02:58 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (None)
    As of 2022-01-26 06:15 GMT
    Find Nodes?
      Voting Booth?
      In 2022, my preferred method to securely store passwords is:

      Results (69 votes). Check out past polls.