http://qs321.pair.com?node_id=1142158


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.