Subarrays with distinct elements

I am getting the wrong ans when using multiplicative modulo inverse,please tell the mistake!

Here is the code https://ide.codingblocks.com/s/117525

Latest update https://ide.codingblocks.com/s/117527

Hello @ratik_puri,

Can you explain the following statement and the usage of power function:
long long sum=((a%mod)*((long long)power(2,mod-2)%mod))%mod;

The value that you are calculating as sum has the following formula:
sum=(len*(len+1))/2

Hope, this would help.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.