Three Machines
Time limit2sMemory limit512 MB
Count pairs (a,b) with 1 <= a < b <= m from which three rewrite operations on integer pairs can generate every card (1, a_i).
- Level
Hard8 of 10
- Topics
- Math, Number theory, Greedy, Implementation
- Solved
- No attempts yet
Problem
In Spaceman Spoof's Functions, Abhilash, Brian, and you, Spaceman Spoof, were able to escape from the evil Zargons. However, there wasn't room for Aditya, the fourth member of their team, leaving him in a precarious situation. He is locked in a Zargon jail cell with three strange machines and a single unmarked card. To get out of the room, he needs to pass through a series of locked doors, each of which require a card with a specific pair of numbers written on it to unlock. Now, Aditya is allowed to write a pair of integers on his card such that for some positive integer . After he does this, he can make use of three different machines in his cell, each of which take in one or two cards and print out a new card, in addition to returning all of the original cards put in:
- The first machine takes in a card with on it and prints a card with on it.
- The second takes in a card with and, if both and are even, prints a card with on it. Otherwise, the machine refuses to print a new card.
- The last takes in two cards with and on them and prints a card with on it.
Aditya has unlimited time so he can use each of these machines as many times as he needs to. The Zargons are very talkative so Aditya was able to learn from his captors that the th locked door can be unlocked by a card with printed on it. Given the array of integers , for how many of the pairs of integers that Aditya writes on his original card would Aditya eventually manage to escape his cell?
Input
The first line of the input consist of two space-separated integers and ), the number of locked doors guarding Aditya's cell, and the maximum value Aditya can write on his original card, respectively.
The next line contains space-separated integers through with . Aditya must manufacture a card with written on it in order to unlock the th door. (The are not necessarily unique.)
Output
Print the number of starting cards , with , for which Aditya would be able to manufacture all of the cards needed to escape. It is guaranteed that the answer will fit in a C++ long long.