It is neither unethical nor illegal to use such maths tricks as long as you are not using any dishonest means like copying from another student or bringing in learning material to the examination hall.