#素因数分解 def Prime_Factorization(N): if N<0: R=[[-1,1]] else: R=[] N=abs(N) if N&1==0: C=0 while N&1==0: N>>=1 C+=1 R.append([2,C]) if N%3==0: C=0 while N%3==0: N//=3 C+=1 R.append([3,C]) k=5 Flag=0 while k*k<=N: if N%k==0: C=0 while N%k==0: C+=1 N//=k R.append([k,C]) k+=2+2*Flag Flag^=1 if N!=1: R.append([N,1]) return R class Grid: def __init__(self,*F): self.F=tuple(F) self.dim=len(self.F) R=[1] for a in self.F[::-1]: R.append(R[-1]*a) self.volume,*self.partition=R[::-1] def number_to_position(self,N): assert 0<=N