Problem · Math
City Infection Number
Learn this problemProblem statement
An infinite row of cities is indexed from 0. Each city is either healthy (0) or infected (1).
On day 1, only city 0 is infected. For every later day, the state of city i is the XOR of the previous-day states of cities i - 1 and i. Treat city -1 as always healthy.
After day n, interpret the city states as a binary number with city 0 as the least significant bit. Return that number modulo 10^9 + 7.
Function
infectedCitiesValue(n: int) → intExamples
Example 1
n = 6return = 51The states from city 0 through city 5 are 1, 1, 0, 0, 1, 1. With city 0 as the least significant bit, the value is 1 + 2 + 16 + 32 = 51.
Example 2
n = 1return = 1Only city 0 is infected on day 1.
Constraints
1 <= n <= 10^6.