时间是一切财富中最宝贵的财富。 —— 德奥弗拉斯多
时间是一切财富中最宝贵的财富。 —— 德奥弗拉斯多
Given a positive integer, N, the sequence of all fractions a/b with (0 < a ≤ b), (1 < b ≤ N) and a and b relatively prime, listed in increasing order, is called the Farey Sequence of order N.
For example, the Farey Sequence of order 6 is:
*0/1, 1/6, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 5/6, 1/1 *
If the denominators of the Farey Sequence of order N are: b, b, . . . , b[K]
then the Farey Sum of order N is the sum of b[i]/b[i + 1] from i = 1 to K—1.
For example, the Farey Sum of order 6 is:
*1/6 + 6/5 + 5/4 + 4/3 + 3/5 + 5/2 + 2/5 + 5/3 + 3/4 + 4/5 + 5/6 + 6/1 = 35/2 *
Write a program to compute the Farey Sum of order N (input).
Mrs. Chambers always has her class line up in height order (shortest at the front of the line). Every September a new class of exactly 20 3rd graders arrive, all of different height. For the first few days it takes a long time to get the kids in height order, since no one knows where they should be in the line.
Needless to say, there is quite a bit of jockeying around. This year Mrs. Chambers decided to try a new method to minimize this ordering chaos. One student would be selected to be the first person in line. Then, another student is selected and would find the rst person in the line that is taller than him,and stand in front of that person, thereby causing all the students behind him to step back to make room. If there is no student that is taller, then he would stand at the end of the line. This process continues, one student at-a-time, until all the students are in line, at which point the students will be lined up in height order.
For this problem, you will write a program that calculates the total number of steps taken back during the ordering process for a given class of students.
ZYB loves binary strings (strings that only contains
1’). And he loves equal binary strings more, where the number of
0and the number of
1 in the string are equal.
ZYB wants to choose a substring from an original string
T so that it is an equal binary stringwith the longest length possible. He also wants to choose a subsequence of
T which meets the same requirements.
v is a substring of a string
v is empty, or there are two integers
r (1≤l≤r≤∣w∣) such that
v=wl*wl+1 ⋯wr A string v is a subsequence of a string
w if it can be derived from w by deleting any number (including zero) of characters without changing the order of the remaining characters.
For simplicity, you only need to output the maximum possible length. Note that the empty string is both a substring and a subsequence of any string.
One day he got a string consisted of numbers. He wants to know how many substrings in the string are multiples of 300 when considered as decimal integers.
Note that leading and trailing zeros are allowed (both in original string and substrings you chose) and the same substring appearing in different places can be counted multiple times.