Skip to content

austin20010423/zero-judge-e626

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

zero-judge-e626

#1. 解題過程: 題目要求->任何正整數都可以寫為多個連續整數的總和。 例如: 15 = 1 + ... + 5 = 4 + ... + 6 = 7 + ... + 8 = 15 + ... + 15 給定一個正整數n,請輸出總和為n的連續正整數? 如果有多組解答,請輸出最多數字的那組。

解題思路:利用快速因式分解的方式節省多次迴圈得時間 -因為是一串連續的數字相加的結果,所以可以設兩邊的數字為邊界,利用梯形公式求得加總的原理 --> (y + x) * (y - x + 1) / 2 = n (梯形公式) --> (y + y - d + 1) * (y - y + d - 1 + 1) = 2n --> (2y - d + 1) * (d) = 2n --> 2y - d + 1 = 2n/d 此時假設 2n 可以整除 d 才有解

參考文件:https://zerojudge.tw/ShowThread?postid=20592&reply=0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages