We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Easy solution in Python-3
'''
T = int(input().strip())
for _ in range(T):
T_th_n = int(input().strip())
N = ((1 + 8*T_th_n)**0.5-1)/2
if N == int(N):
print(int(N))
else:
print(-1)
'''
Approach:-
The code uses a for loop to iterate over a range of T test cases. For each test case, it takes an input T_th_n and calculates N using a mathematical formula. If N is an integer, it prints the integer value of N. Otherwise, it prints -1. The approach seems to be solving a mathematical problem related to finding the value of N.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #42: Coded triangle numbers
You are viewing a single comment's thread. Return to all comments →
Easy solution in Python-3 ''' T = int(input().strip()) for _ in range(T): T_th_n = int(input().strip()) N = ((1 + 8*T_th_n)**0.5-1)/2 if N == int(N): print(int(N)) else: print(-1) '''
Approach:-
The code uses a for loop to iterate over a range of T test cases. For each test case, it takes an input T_th_n and calculates N using a mathematical formula. If N is an integer, it prints the integer value of N. Otherwise, it prints -1. The approach seems to be solving a mathematical problem related to finding the value of N.