Message Boards Message Boards

[✓] Get the number of Integers coprime to X less than Y?

GROUPS:

Wolfram understands Coprime/relatively prime and will output a list of integers if you input something like:

integers | coprime to 35

But it doesn't seem to let you do anything else with the coprime function. I want to be able to do things like count the number of integers coprime to a number X less than Y, or in a range [k, k+-Y]

I've tried things like this:

integers | less than 20 | coprime to 35

Intersection[ {integers less than 20}, {integers | coprime to 35}]

But nothing seems to work. If anyone can give me some help that would be great.

Thanks in advance.

POSTED BY: Sam Parker
Answer
1 month ago

Hi,

this (pure) function tests whether a particular number is coprime to 35 and smaller than 20.

CoprimeQ[35, #] && # < 20 &

You can apply this to all function in a certain range:

Select[Range[-100, 100], CoprimeQ[35, #] && # < 20 &]

Of course this is not quite necessary, because technically we can add the range restriction in the first place to the input:

Select[Range[-100, 19], CoprimeQ[35, #] &]

gives the same as above.

Cheers,

Marco

POSTED BY: Marco Thiel
Answer
1 month ago

Thanks Marco! Exactly what I wanted

POSTED BY: Sam Parker
Answer
1 month ago

[✓] Get the number of Integers coprime to X less than Y?

POSTED BY: Sam Parker
Answer
1 month ago

Group Abstract Group Abstract