PROBLEM LINKS
DIFFICULTY
EASY
EXPLANATION
Part 1 closed form: (3^n+1)/2 - 2^n
Part 2 closed form: 2*4^(n-1) - 3^n + 2^(n-1) + 2^n - (3^n+1)/2
The answer (for both 1 and 2) is in the form of a * 4^n + b * 3^n + c * 2^n + d for some small constants a,b,c,d.
You can calculate 4^n%MOD, 3^n%MOD, 2^n%MOD in log(n) time using fast exponentiation for an overall complexity of O(log(n)).
SETTER'S SOLUTION
Can be found here.
TESTER'S SOLUTION
Can be found here.