diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-01-12 21:35:03 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-01-13 11:37:17 +0700 |
commit | 1fca99158c60a94497b21ff527d4071d96c9c0f1 (patch) | |
tree | 3b6533c4c5fa4f67a6ae0fffdf042f4b46a749e6 /others/other/diffsum.py | |
parent | 7c9b47ab9149d292d5493c865dfb8742a7450472 (diff) | |
download | cp-1fca99158c60a94497b21ff527d4071d96c9c0f1.tar.gz |
others/other: Add diffsum.{py,pas} and lseq.c
Diffstat (limited to 'others/other/diffsum.py')
-rwxr-xr-x | others/other/diffsum.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/others/other/diffsum.py b/others/other/diffsum.py new file mode 100755 index 0000000..697db0c --- /dev/null +++ b/others/other/diffsum.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +with open("DIFFSUM.INP") as f: + n = int(f.readline()) + +a = list(range(2, int((n * 8 + 9) ** 0.5 - 3) // 2 + 1)) +a.append(n - sum(a)) + +while len(a) > 1 and a[-1] - a[-2] > 2: + for i in reversed(range(1, len(a))): + delta = (a[i] - 1 - a[i - 1]) // 2 + if delta > 0: + a[i] -= delta + a[i - 1] += delta + +with open("DIFFSUM.OUT", "w") as f: + f.write(' '.join(map(str, a)) + '\n') |