while True:
n, x = map (int, input (). split ())
if n == x == 0:
break
cnt = 0
for a in range (1, x // 3):
for b in range (a + 1, x // 2):
c = x a b
if b<c<= n:
cnt + = 1
print (cnt)
The above code is the code that came out by googled the solution of the problem of AIZU ONLINE JUDGE.
Number of combinations
From the numbers from 1 to n, select 3 numbers without duplication and create a program to find the number of combinations whose sum is x.
For example, a combination of 3 numbers from 1 to 5 that add up to 9
1 + 3 + 5 = 9
2 + 3 + 4 = 9
There are two ways.
Input
Multiple datasets are given as input. For each dataset, whitespaceseparated n, x are given on one line.
When both n and x are 0, the input ends.
Constraints
3 ≤ n ≤ 100
0 ≤ x ≤ 300
Output
For each dataset, output the number of combinations on one line.
I think it's very compact and amazing, but I don't understand why cnt is incremented when "b

Answer # 1

Answer # 2
The point is that the three numbers are a for the smallest number, b for the next number, and c for the largest number.
Then, if a and b are changed, c is sought and it is checked whether it is within n.When a and b are decided, c = xab and c are decided.
If c is greater than b and less than or equal to n, it is valid.Since a is the smallest number, adding the remaining b and c will increase it by at least 3 times.
Checking up to 1/3 of x is sufficient.
If b is less and c larger than b is added, it will be doubled, so checking up to 1/2 of x is sufficient.Separately, you can check a from 1 to x and b from a + 1 to x, but for the above reason, if a, there is nothing that exceeds 1/3.
Related articles
 python 3x  how to count the number of data extracted by pandas or how to solve the error
 python 3x  i want to output the name corresponding to the number entered in the excel file
 where is the minor version number of python that starts by default specified?
 python  when you want to judge by the number of characters from the back with a regular expression
 python  how to get the number of searches for a specific word within the period
 python  sumy by specifying the maximum number of characters with sumy
 python  i want to add a line number to the data frame
 python  i want to divide a binary number into two, store it in a list, and represent it in a different decimal number
 python  how to accept number input even if keypressevent is defined for qlineedit in pyside
 i want to invert the number 12345 in python like 54321 and display it
 get the number of characters from the python text box
 get the total number and name of python grouping
 how to align the number of elements with overlaplengt of python etc
 set python excel serial number to date and time
 how to multiply each element by a number in a python 2d list
 how to write to count the number of specific elements of dictionary values in python3
 python  valueerror: field'id' expected a number but got'suzukitadashi'
 python  does the number of arguments match?
 python  how to count the number of characters in a character string including a regular expression
Trends
a
The value of1
From "Total valuex
While changing to a number smaller than onethird ofb
The value ofa + 1
From "Total valuex
While changing to a number less than half ofObtained by calculation (x a b)
c
The value ofb
Larger andn
IsThen the total is
x
Combination to bea, b, c
Because you have found a pair.Supplement:
Choosing three numbers from integers from 1 to n (not explicitly stated in the question sentence, but sure from the following sentences and examples) without duplication
Since each of the three integers is different, a magnitude relationship holds.
about it. So, in the blog that presents the solution,
Each of the three unique integers
a
,b
,c
ToFor convenience,
aSuppose that the relationship of
It is said. In other words, the smallest of the three integers
a
, The second smallest oneb
, The third smallestc
Treat as.Then
a
Is "at least the total valuex
It is less than onethird of. " Becausea
And bigger than thatb
Orc
And the totalx
Because it has to be (if you allow duplication, the total valuex
Onethird ofa
Is the upper limit of).b
The value ofa
Must be greater than the value ofx
Froma
It also needs to be less than half the number minus the value of. Becauseb
And bigger than thatc
The total with and is "total valuex
Froma
This is because it must be "the number obtained by subtracting the value of" (if duplication is allowed, the total valuex
Froma
Half of the number minus the value ofb
Is the upper limit of).c
The value of is "total valuex
Froma
With the value ofb
It is calculated by "the number obtained by subtracting the value of".b
Need to be larger, yetn
Must be:To search for the above efficiently
range
Specify a range of integers with, and when the condition is met (initial value 0)cnt
Increase by 1 to get the final number of combinations.cnt + = 1
Indented the same amount on the line immediately afterprint (f "{a} {b} {c}")
If you try adding, the combinations found will be displayed, which will give you a better understanding.