How to calculate minimum n less than c for which -> a^n % c = d

How to calculate minimum n less than c for which -> a^n % c = d holds true;
here c is a prime number and other values except n are known.

sorry bro its not fair to ask questions from the ongoing contest.
it is not fair to ask questions regarding the concept about a question related to a live contest.
the question should be removed.
this question is from hackerearth’s june circuits (dexter with gp).

Okay, How do you delete a question? I will remove it