IntuitOA #4
Coloring a Grid — n × 3 with R/G/B
Estimated HardJudge-ready
Topics (AI-labelled)Bits & MathState Machines
Color an n×3 grid with three colors: red, green, and blue. A valid coloring requires every row and every column to contain at least two colors. The source's sample outputs for n=3 and n=4 contradict the statement; following the statement, they are corrected to 9750 and 296490 respectively.
Input
A single integer n (site range 1≤n≤10^18).
Output
Output the number of valid colorings modulo 1,000,000,007.
Example 1
Input:
2
Output:
174
Example 2
Input:
3
Output:
9750
Example 3
Input:
4
Output:
296490
Example notes
Apply inclusion-exclusion to the events that each of the three columns is entirely one color; the answer is 24^n−9·8^n+9·2^n+18·3^n−24 (modulo).
Editorial
Loading solution…