How to know if a number is in a collection of numbers in pari?

78 views Asked by At

I use pari most of the time for my computational number theory research. I entered the following: for(x=1,100,print1(eulerphi(n)-1))
which gives the values of φ(n)-1 for integers 1 to 100. Here φ(n) is the number of integers less than n which are relatively prime to n. It gave the following output:
0 0 1 1 3 1 5 3 5 3 ... 65 31 43 23 69 2 43 59 45 71 31 95 41 59 39
(I excluded some integers to make the question short) I want to check if a number is in those numbers. How can I do so?

1

There are 1 answers

3
Piotr Semenov On BEST ANSWER

You can use function setsearch to perform binary search through sorted list. It returns the 1-based index of match or 0 if nothing is found. Your example is here:

xs = Set(vector(100, n, eulerphi(n)-1))
> [0, 1, 3, 5, 7, ..., 87, 95]

setsearch(xs, 4)
> 4

setsearch(xs, 20)
> 0