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.
Project Euler #98: Anagramic squares
Project Euler #98: Anagramic squares
Sort by
recency
|
20 Discussions
|
Please Login in order to post a comment
C++
Only test case 10 fails due to timeout error. I tried submitting in pypy3 too. Annoying. Any help?
why is test case 0 is failing and rest all are passing? isn't the testcase with N=4? i am able to test my code for N=4 with correct answer of 9216. I am not sure what am i missing.
Hints:
1) For each N, you only need to loop from 10^((N-1)/2) to 10^(N/2). For example: N=4, i runs from 31 to 100. Then take i^2. That saves a lot of time complexity compared with i running from 1000 to 10000 and then taking square root.
2) A nice trick to store all permutations in any permutation problems: create a dictionary, convert satisfied number as a sorted key. For example: {'1269': [1296, 2916, 9216]}, where '1269' is sorted key of 1296, 2916 and 9216
I followed a simpler approach, I precomputed all the answers and stored it, and just responded to the queries...
for the hash function i used the descending order of digits.