Archith loves to play with number series. Archith asked his girlfriend to a date. But…
- User
Archith loves to play with number series. Archith asked his girlfriend to a date. But she was busy in solving the homework on triangular series which stated that find the least number which has higher divisors than n in a triangular series. His girlfriend made a condition that if he solves this assignment for her she will come for date. Archith dont want to waste time he is developing a code. Put yourself in the position of archith and solve this problem.(#projecteuler 13) INPUT: T test cases every t lines consists of a number n which specifies the no of divisors. OUTPUT: output the least triangular number which has higher no of divisors than n.
1<T<11 1<n<10^2
example:
triangular series will be as follows 1,3,6,10........ if n =2 6 has 4 divisors.So 6 will be the least number to have more than n divisors.
SAMPLE INPUT 4 1 2 3 4
SAMPLE OUTPUT 3 6 6 28
Assistant
pythondivisors_cache = {} def count_divisors(m): if m in divisors_cache: return divisors_cache[m] original = m if m == 0: return 0 count = 1 i = 2 while i * i <= m: exponent = 0 while m % i == 0: exponent += 1 m = m // i if exponent > 0: count *= (exponent + 1) i += 1 if m > 1: count *= 2 divisors_cache[original] = count return count def precompute_answers(): ans = [None] * 101 # indexes 1 to 100 remaining = 100 k = 1 while remaining > 0: if k % 2 == 0: part1 = k // 2 part2 = k + 1 else: part1 = k part2 = (k + 1) // 2 d1 = count_divisors(part1) d2 = count_divisors(part2) d = d1 * d2 T = part1 * part2 upper = min(d, 101) for m in range(1, upper): if ans[m] is None: ans[m] = T remaining -= 1 if remaining == 0: break if remaining == 0: break k += 1 return ans ans = precompute_answers() import sys input = sys.stdin.read().split() T = int(input[0]) for n in map(int, input[1:T+1]): print(ans[n])
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.