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.
- Prepare
- Python
- Math
- Triangle Quest 2
- Discussions
Triangle Quest 2
Triangle Quest 2
Sort by
recency
|
1170 Discussions
|
Please Login in order to post a comment
n = int(input()) for i in range(1, n+1): print(int("1" * i) ** 2)
I didn't crack it. I admit. But this is more of a math trick problem than a python programming problem.
It was easy to crack as its all power and its reciprocal to retrace the steps for the solution i.e. if take square root of each number it is a squence of 1. e.g.
Hence the solution:
print ((pow(10,i)//9)**2)
The logic is: For i=3 the numbers = [1,2,3,2,1] and enumerate([1,2,3,2,1]) = [(0,1), (1,2), (2,3), (3,2), (4,1)]. For each (index, value) : value * 10^(length-1-index) (0,1): 1 * 10^(5-1-0) = 1 * 10^4 = 10000 (1,2): 2 * 10^(5-1-1) = 2 * 10^3 = 2000
(2,3): 3 * 10^(5-1-2) = 3 * 10^2 = 300 (3,2): 2 * 10^(5-1-3) = 2 * 10^1 = 20 (4,1): 1 * 10^(5-1-4) = 1 * 10^0 = 1 Sum: 10000 + 2000 + 300 + 20 + 1 = 12321 """
Read input
n = int(input())
Apply conditional logic
if n % 2 != 0: print("Weird") elif 2 <= n <= 5: print("Not Weird") elif 6 <= n <= 20: print("Weird") else: print("Not Weird")