Is my approach correct?
@supratik260699 yes your approach is correct but you need to store results in long long int as they may increase int limit.
@supratik260699 yes your approach is correct but you need to store results in long long int as they may increase int limit.