PROBLEM LINK:
Shinji Ikari and Beautiful Images
Setter: sayan_kashyapi
Tester: sayan_kashyapi
Editorialist: sayan_kashyapi
DIFFICULTY:
Easy
PREREQUISITES:
Permutation-Combination
PROBLEM:
There was a image of N\times N pixel which contains one of three colors, Red, Green, Blue. A image is considered to be as beautiful if all three colors are present in at least one of the pixels of the image. Find out the number of beautiful images.
QUICK EXPLANATION
The number of beautiful images will be = 3^{N^2} - 3(2^{N^2} - 1)
TIME COMPLEXITY
Time complexity is O(N) for each test case.
SOLUTIONS:
Setter's Solution
PYTH 3.6
MOD=1000000007
t=int(input())
for i in range(t):
n=int(input())
print((((3 ** (n * n))) - 3 * (((2 ** (n * n))) - 1)) % MOD)
Tester's Solution
PYPY3
MOD=1000000007
t=int(input())
for i in range(t):
n=int(input())
print((((3 ** (n * n))) - 3 * (((2 ** (n * n))) - 1)) % MOD)
Feel free to share your approach.
Suggestions are welcomed as always had been.