有问题试图平均系数时间(pr)的值,将2个素数的因子分解成倍。 目前它使用一次迭代,但不确定如何使其与n次迭代一起工作。
require("gmp")
prime<-function(a) {
pr <- vector(mode = "numeric", length = a)
sz <- vector(mode = "numeric", length = a)
for(i in 1:a){
y<-urand.bigz(nb = 2, size = i)
p1<-nextprime(as.bigz(y[1]))
p2<-nextprime(as.bigz(y[2]))
p<-p1*p2
pr[i] <-system.time(factorize(p))[1]
sz[i] <-sizeinbase(p)
}
return(cbind(sz,pr))
}
times <- prime(48)
plot(times,xlab="Size of Psuedoprime ",ylab="Time taken to factorize", main="Size of Vs Time taken to factorize of a given Pseudoprime")
任何帮助将不胜感激
答案 0 :(得分:0)
我认为这就是你要找的东西。
prime<-function(a) {
pr <- vector(mode = "numeric", length = sum(a))
sz <- vector(mode = "numeric", length = sum(a))
for(j in 1:length(a)){
for(i in 1:a[j]){
y<-urand.bigz(nb = 2, size = i)
p1<-nextprime(as.bigz(y[1]))
p2<-nextprime(as.bigz(y[2]))
p<-p1*p2
if(j == 1){
pr[i] <-system.time(factorize(p))[1]
sz[i] <-sizeinbase(p)
}else{
pr[sum(a[1:(j-1)]) + i] <- system.time(factorize(p))[1]
sz[sum(a[1:(j-1)]) + i] <-sizeinbase(p)
}
}
}
return(cbind(sz,pr))
}
times <- prime(c(48, 52))