Some time ago my cousin to a math problem, I want to help him. I looked for to do before I really had to spend doing something, now python, and I easily solved, take a look at what the topic is not it!
analysis:
这里有我自己整理了一套最新的python系统学习教程,
包括从基础的python脚本到web开发、爬虫、数据分析、
数据可视化、机器学习等。小编这里推荐加小编的python学习群:895,817, 687
The questions added two points on the basis of the general rule on the question:
① Zhengshi involves simple arithmetic.
② with S1, S2, S3, S4, S5 ... are represented each, candidates will have an incentive to mislead the front row and the n items of its geometric and arithmetic in the "Sn" confusion as to increase the difficulty of questions.
③ individual expression needs to rely on a result, increase the difficulty of questions.
Third, the conventional problem-solving ideas:
Step: According to the first expression, each expression were calculated back, until the discovery rule.
Step Two: Analysis of the law, summed up the law, calculated in accordance with the law of the target item.
To do:
First, were obtained every front: easy to find the law
S1 = 1/a
S2 = -s1-1 = -(1/a)-1 = -(a+1)/a
S3 = 1 / s 2 = -a / (a + 1)
S4 = -s3-1 = a / (a + 1) -1 = -1 / (a + 1) initial signs
S5 = 1 / s4 = - (a + 1) = -a-1 bit mean
S6 = -s5-1 = - (- a-1) -1 = a looming
S7 = 1 / s6 = 1 / a understood why
S8 = ...
Second, analysis of the law
Obviously, Item 8: - (a + 1) / a, Item 9: -a / (a + 1), item 10 is: -1 / (a + 1), i.e., item 11 ... expressions are circulating behind the term of the former six.
So, the requirement 2018, 2018 is determined that only the first six of which one can in the process cycle.
Method: In addition to 6 further modulo 2018, and the remainder is 2, then the further cycle through several rounds of single colonies twice, the first six in the control, the second term is a - (a + 1) / a, so the answer is - (a + 1) / a
Third, code implementation
Next we use the program to achieve:
method one:
To simulate operation 2018 times, while the outermost layer so we kept to achieve the cycle, while repeating traverse the inside of the six results were for.
Code:
Effect:
This method though is realistic simulation of the 2018 cycle traversal, but really in trouble, then we use modulo (that is, take the remainder) way to achieve the above functions.
Method Two:
Code:
Effect:
how, instantly eliminating the need for secondary operations 2016, but also to streamline the code, is not cool.
But our computers, but most are not afraid of hard work, and it is the best at doing repetitive operation, it encountered a similar math problems, we can also threw a computer.