Immersion into the Animus
Time limit2sMemory limit1024 MB
Given n and k, count the unordered pairs of distinct natural numbers, each at most n, that sum to k.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
The Animus is a complex machine that reads a person's genetic memory and projects it in 3D.
For simplicity, assume that every cell in the body and every event has a unique code, a natural number. The algorithm that computes these codes belongs to Abstergo Industries and is not disclosed. Cell codes are numbered consecutively.
To read the information of an event with code , the Animus searches for all pairs of cells whose codes do not exceed and whose codes sum to . For example, when reading event with , there is exactly one suitable pair, the cells with codes and . If and , no pair exists, because cell codes do not repeat.
Before Dr. Sofia Rikin immerses Callum Lynch into Spain in 1492, she wants to know how many pairs of cells the Animus will find. The Animus has no function for counting this, so given and , count the pairs of distinct natural numbers that do not exceed and sum to .
Input
The first line contains two natural numbers and : the upper limit on a cell code and the sum of the codes of the pairs to find, respectively ().
Output
Print one line with the number of pairs of distinct natural numbers that do not exceed and sum to .
Hint
For working with numbers greater than , a 64-bit integer type is recommended.