Find a simple formula of k numbers which gives output a number not among these k numbers.

45 Views Asked by At

This question just came to my mind while thinking. I just wanted to know if it is even possible. Anyway, the question goes as follows.

You are given k numbers $a_{i}$ (k < n) from 1 to n.

Your job is to give a simple formula represented as a function f($a_{1}, a_{2}, .., a_{k}$) which gives a number N $\in$ {1, 2, .., n} such that N $\neq$ $a_{i}$ for any i $\in$ {1, 2, .., k}

My approaches(which obviously have failed :P) :

  1. ($\sum_{i=1}^{k}a_{i})$ % n + 1

  2. ($\prod_{i=1}^{k}a_{i}$) % n + 1

  3. (xor all of them) % n + 1

  4. (and all of them) % n + 1 && (or all of them) % n + 1

I tried above approaches because they are similar to Euclid's proof that primes are infinite. This question seems to be related to abstract algebra, but I am still learning it so pardon me if I may have made a dumb mistake.

By "simple" I mean operations that can be performed in O(1) like +, -, x, /, xor, |, &, ...

1

There are 1 best solutions below

6
On

You can do $f(K) = \min\{\{1,\dots,n\} \setminus K\} $ where $K=\{a_1,\dots\}$.