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]) for n_str in data[1:T+1]: N = int(n_str) term3 = pow(3, N, MOD) term2 = (3 * pow(2, N, MOD)) % MOD res = (term3 - term2 + 3) % MOD print(res) 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.