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
pythonimport math def count_divisors(x): if x == 0: return 0 cnt = 0 sqrt_x = int(math.sqrt(x)) for i in range(1, sqrt_x + 1): if x % i == 0: if i * i == x: cnt += 1 else: cnt += 2 return cnt def precompute_answers(): answers = [None] * 100 # Indexes 0-99 correspond to n=1-99 filled = 0 k = 1 max_n = 99 while filled < max_n: t_k = k * (k + 1) // 2 if k % 2 == 0: a = k // 2 b = k + 1 else: a = (k + 1) // 2 b = k da = count_divisors(a) db = count_divisors(b) d = da * db for i in range(1, d): if i >= 100: continue if answers[i] is None: answers[i] = t_k filled += 1 if filled == max_n: break if filled == max_n: break k += 1 return answers # Precompute the answers for all n from 1 to 99 answers = precompute_answers() # Read input and output results T = int(input()) for _ in range(T): n = int(input()) print(answers[n])
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.