We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
unsigned long long int is not enough to store n^2 value for test cases 5 and 6. Therefore (at least in C) we need to use modular arithmetic. There is a multiplication rule, that says:
(ab)%n = ((a%n)*(b%n))%n
So in our case it's ((read_number%1000000007)^2)%1000000007
Summing the N series
You are viewing a single comment's thread. Return to all comments →
unsigned long long int is not enough to store n^2 value for test cases 5 and 6. Therefore (at least in C) we need to use modular arithmetic. There is a multiplication rule, that says: (ab)%n = ((a%n)*(b%n))%n So in our case it's ((read_number%1000000007)^2)%1000000007