[Solution] Majority Codeforces Solution | Solution Codeforces
Everyone was happy coding, until suddenly a power shortage happened and the best competitive programming site went down. Fortunately, a system administrator bought some new equipment recently, including some UPSs. Thus there are some servers that are still online, but we need all of them to be working in order to keep the round rated.
Imagine the servers being a binary string of length . If the -th server is online, then , and otherwise.
A system administrator can do the following operation called electricity spread, that consists of the following phases:
- Select two servers at positions such that both are online (i.e. ). The spread starts only from online servers.
- Check if we have enough power to make the spread. We consider having enough power if the number of turned on servers in range is at least the number of turned off servers in range . More formally, check whether .
- If the check is positive, turn on all the offline servers in range . More formally, make for all from to .
We call a binary string of length rated if we can turn on all servers (i.e. make for ) using the electricity spread operation any number of times (possibly, ). Your task is to find the number of rated strings of length modulo .
The first and only line contains two integers and (, ) — the length of the string and the required module.
Print a single integer — the number of rated binary strings of length . Since this number can be large, print it modulo .
In the first example, the only rated string is 11. So the answer is .
In the second example, the rated strings are:
- 111;
- 101, because we can perform an operation with and .
So the answer is .
In the third sample, the rated strings are:
- 1001;
- 1111;
- 1011;
- 1101.
So the answer is .
No comments:
Post a Comment