From ce56bd193a7c8c6437443227cd3abb51134e3e7a Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 14 Jan 2019 20:41:09 +0700 Subject: At least I managed to stay in top 10% --- codechef/eartseq.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 codechef/eartseq.py (limited to 'codechef/eartseq.py') diff --git a/codechef/eartseq.py b/codechef/eartseq.py new file mode 100755 index 0000000..bb6258b --- /dev/null +++ b/codechef/eartseq.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +from math import gcd +from itertools import cycle, islice +from sys import stdin + +CANDIDATES = cycle(range(2, 30000)) + +a, b, new = 30011, 30013, {} +coprimes, result = [a, b], [a * b] +for _ in range(49998): + for i in CANDIDATES: + if new.get(b * i, True) and gcd(a, i) == 1 == gcd(b, i): + coprimes.append(i) + a, b = b, i + break + new[a * b] = False + result.append(a * b) + +next(stdin) +for N in map(int, stdin): + N -= 1 + print(coprimes[N] * 30011, end=' ') + print(*islice(result, N)) -- cgit 1.4.1