Project Euler #62: Cubic permutations

Sort by

recency

|

7 Discussions

|

  • + 1 comment

    I don't understand why my code doesn't work?!

    from collections import defaultdict
    d=defaultdict(lambda:[])
    
    n,k=map(int,input().split(' '))
    
    l=[]
    for i in range(1,n):
        temp=i*i*i
        s="".join(sorted(str(temp)))
        d[s].append(i)
        if len(d[s])==k:
            #d[s].sort()
            l.append(pow(min(d[s]),3))
        
    #print(d)
    new=sorted(l)
    for v in new:
        print(v)
    
  • + 0 comments

    Hint: Try to use hash/dictionary to store data, then you can save a lot of running time!

    For example: {'01234566': [41063625, 56623104, 66430125]} within:

    41063625 = 345^3; 56623104 = 384^3; 66430125 = 405^3

    '01234566' is a sorted string that contains all digits

  • + 0 comments

    If you're failing tests 0, 3, 5 but passing all others it's probably because you included entries larger than n in your permutations. For example, {1, 2, 3} is k=3, but for n = 2, k for the list is only 1 as both 2 and 3 are larger or equals to n.

  • + 1 comment

    Hi, can anyone please give more testcases with max valus of N and K? I am failing test-cases from #5 to #9.

  • + 2 comments

    please suggest improvements.....can only pass 0 and 1st cases

    i=0;
    cubes=[]
    n,k=map(int,input().split(' ',1))
    while(1):
        cube=sorted(list(str(i**3)))
        cubes.append(cube)
        if(cubes.count(cube)==k):
            print(pow(cubes.index(cube),3))
            break
        i=i+1