@jjallan/

OlivedrabIllinformedOxen

Python 2.7

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
h=lambda n,v=1,x=1:v and(n>=v and h(n,v*x,x+1)or(v,x-1))or n and h(n-1,0,n*x)or x
i=lambda p,j=0,r=0:j<len(p)and i(p,j+1,r+sum(k<p[j]for k in p[j+1:])*h(len(p)-j-1,0))or r
def f(n):t,x=h(n);g=range(x);o=g[:];r=[];exec"t/=x;x-=1;r+=[o.pop(n/t)];n%=t;"*x;return i([r.index(v)for v in g])

for test in (0,1,2,3,4,5,6,13,42,100,1e3,1e4,1e5,5e6,1e7,1e8,1e9,1e10,1e22):
	print int(test), ':', f(int(test))