Given an integer N,Find how many strings of length N are possible, consisting only of…
- User
Given an integer N,Find how many strings of length N are possible, consisting only of characters { 'A','B' and 'C' } with each character {'A','B' and 'C'} occurs at least once. Input: First line of each test case contains number of test cases T. Each test case contains a single integer N.
Output: For each test case print the expected output. Output may be too large so print it modulo 10^9+7.
Constraints: 1 ≤ T ≤ 10^5 1 ≤ N ≤ 10^9
SAMPLE INPUT 3 2 3 4
SAMPLE OUTPUT 0 6 36
Assistant
pythonMOD = 10**9 + 7 import sys def main(): input = sys.stdin.read data = input().split() T = int(data[0]) results = [] for i in range(1, T + 1): N = int(data[i]) pow3 = pow(3, N, MOD) pow2 = pow(2, N, MOD) res = (pow3 - 3 * pow2 + 3) % MOD results.append(res) print('\n'.join(map(str, results))) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.