From 1fca99158c60a94497b21ff527d4071d96c9c0f1 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Thu, 12 Jan 2017 21:35:03 +0700 Subject: others/other: Add diffsum.{py,pas} and lseq.c --- others/other/diffsum.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 others/other/diffsum.py (limited to 'others/other/diffsum.py') 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') -- cgit 1.4.1