素因数分解

r.elem <- sample(2:4,3)
r.num <- sample(1:3,length(r.elem),replace=TRUE)

M <- prod(r.elem^r.num)
library(gmp)
ff <- factorize(M)
n.iter <- 10
for(i in 1:n.iter){
	s <- sample(2:(length(ff)-1),1)
	ss <- sample(1:s,length(ff),replace=TRUE)
	ss[1:s] <- 1:s
	Rs <- rep(1,s)
	for(j in 1:s){
		Rs[j] <- as.numeric(prod(ff[which(ss==j)]))
	}
	print(prod(Rs))
	print(prod(Rs-1))
}