Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Prime-decomposition/R/prime-decomposition-1.r
Normal file
15
Task/Prime-decomposition/R/prime-decomposition-1.r
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
findfactors <- function(num) {
|
||||
x <- NULL
|
||||
firstprime<- 2; secondprime <- 3; everyprime <- num
|
||||
while( everyprime != 1 ) {
|
||||
while( everyprime%%firstprime == 0 ) {
|
||||
x <- c(x, firstprime)
|
||||
everyprime <- floor(everyprime/ firstprime)
|
||||
}
|
||||
firstprime <- secondprime
|
||||
secondprime <- secondprime + 2
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
print(findfactors(1027*4))
|
||||
35
Task/Prime-decomposition/R/prime-decomposition-2.r
Normal file
35
Task/Prime-decomposition/R/prime-decomposition-2.r
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
primes <- as.integer(c())
|
||||
|
||||
max_prime_checker <- function(n){
|
||||
divisor <<- NULL
|
||||
|
||||
primes <- primes[primes <= n]
|
||||
|
||||
for(i in 1:length(primes)){
|
||||
if((n/primes[i]) %% 1 == 0){
|
||||
divisor[i]<<-1
|
||||
} else {
|
||||
divisor[i]<<-0
|
||||
}
|
||||
}
|
||||
num_find <<- primes*as.integer(divisor)
|
||||
|
||||
return(max(num_find))
|
||||
}
|
||||
|
||||
#recursive prime finder
|
||||
prime_factors <- function(n){
|
||||
|
||||
factors <- NULL
|
||||
|
||||
large <- max_prime_checker(n)
|
||||
n1 <- n/large
|
||||
|
||||
if(max_prime_checker(n1) == n1){
|
||||
factors <- c(large,n1)
|
||||
return(factors)
|
||||
} else {
|
||||
factors <- c(large, prime_factors(n1))
|
||||
return(factors)
|
||||
}
|
||||
}
|
||||
19
Task/Prime-decomposition/R/prime-decomposition-3.r
Normal file
19
Task/Prime-decomposition/R/prime-decomposition-3.r
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
findfactors <- function(n) {
|
||||
a <- NULL
|
||||
if (n > 1) {
|
||||
while (n %% 2 == 0) {
|
||||
a <- c(a, 2)
|
||||
n <- n %/% 2
|
||||
}
|
||||
k <- 3
|
||||
while (k * k <= n) {
|
||||
while (n %% k == 0) {
|
||||
a <- c(a, k)
|
||||
n <- n %/% k
|
||||
}
|
||||
k <- k + 2
|
||||
}
|
||||
if (n > 1) a <- c(a, n)
|
||||
}
|
||||
a
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue