Project Euler #42: Coded triangle numbers

  • + 0 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.