# [C (gcc)], <s>87</s> 86 bytes Saved a byte thanks to the man himself [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)!!! <!-- language-all: lang-c --> i;q;p;m;f(b){for(p=m=b;p|!q;++m)for(q=p=i=1;++i<m;p=p&&m%i)q=m%i?q:q&&b*~-b*~b%i;--m;} [Try it online!][TIO-kg8letz2] [C (gcc)]: https://gcc.gnu.org/ [TIO-kg8letz2]: https://tio.run/##bVFdb4IwFH33V3QkENBLZqlVWO32sOxXqA@CsDVZsXxkIXPsr7OLoG7JSC/l3J5zaE8T/zVJuk6JQhihRebG3ik7lq6RWsbCfN0VYjbTXt8qpJFKUsRqrYWRxnG0rbxC4vupeCgcJ55@@1ixrYTva9F2Kq@J3qvc9SanCcGnb9RpVVebHZHkFACHJdA50ACCFbAA2ALYCkIcIYQR9ikWg2AeteLqkDYmTer0MJpwWAxMnBBwDowDXUY9jug4KGPI4RCEF6fkbV9OSTmYWNvmJdg20TMWt4D8xswaFZgCcfsNqPyQNiibi/FzTSr1mR4z93w4735E0wEKgpn1PI8MMVwOQmI0GfI4r@/EddmUSMhcyz4Q/5HgjmJP/NGWaf2xf0d9f2f/6uxqm6NwIOK8uUjkLcHht7vRoJ203Q8 "C (gcc) – Try It Online" Port of my [Python answer](https://codegolf.stackexchange.com/a/213463/9481).