Wins the offer - and s is the number of consecutive columns

Title Description

Xiao Ming is very fond of mathematics, one day when he was doing math homework, required to calculate and 9 to 16, he immediately wrote the correct answer is 100. But he was not satisfied with this, he wondered how many kinds of continuous positive number sequence is 100 (including at least two numbers). Before long, he got another set of consecutive positive number and a sequence of 100: 18,19,20,21,22. Now the question to you, you can also quickly identify all positive and continuous sequence S? Good Luck!

All positive output and a continuous number sequence S. The ascending order in the ascending sequence between the sequence numbers in accordance with the start ascending order

Thinking

Use the sum formula of arithmetic progression, then find all integers satisfy conditions

class Solution:
    def FindContinuousSequence(self, tsum):
        ans = []
        for i in range(tsum-1):
            n = tsum-i
            if 2*tsum+n > n**2 and (2*tsum+n-n**2)%(2*n)==0:
                first = int((2*tsum+n-n**2)/(2*n))
                temp = [first]
                for j in range(1,n):
                    first += 1
                    temp.append(first)
                ans.append(temp)
        return ans
            

 

Published 82 original articles · won praise 2 · Views 4352

Guess you like

Origin blog.csdn.net/qq_22498427/article/details/104818612