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
|
1184 Discussions
|
Please Login in order to post a comment
WTF? How is this a programming problem?
for i in range(1,int(input())+1): print((10**i//9)**2)
As in the first Triangle Quest, I had no idea this was a known math problem and I went a little crazy
I figured this out
So I tried to build the sum of the powers of ten to power it by
2after:[10]*iget's you a list ofi10srange(i-1,-1,-1)get's you an iterator of the powers fromi-1to0map(pow,[10]*i,range(i-1,-1,-1))will get you an iterator that powers each 10 to each value - given by range() in the same positionlist(...)of the latter result will get you a proper list that you cansum(...)2Or you can just
print(((10**i-1)//9)**2)gives the same thingThis is not really a test of python skills... this is just a math problem. What is the point for someone who is trying to brush up on python?
Looking at the math based solutions, now I understand why there was that strange limit at input below 10. Of course, this method does not work above 10.
Now: find a method which still work above 10 :-)