A number n is evil if:
It is an integer multiple of 6, 13, or 101, or
It is an integer multiple of 3 but not of 9, or
It contains the contiguous digit sequences "6", "13", "101" or "31".
A number n is bad if:
It is evil, or
The sum of its digits is evil, or
N mod 30 is evil.
A number n is good if it is not bad.
A number n is safe if n, n+1, and n-1 are good.
Question: Is there any formula f(n) such that, for all integers n, if n is good then f(n) is good (and f(n) > n so that a series is created) ? How about g(n) such that, for all integers n, if n is safe then g(n) is safe? And is it possible to write these formulae without using any bad constants?