I think my approach is right but test case failed
I have edited your code… Try to submit it now…
The approach was correct, only thing to be done is that you have to use long long int values and also u are supposed to take the mod values at every step ,…Not only in the end…