How to resolve the algorithm Largest proper divisor of n step by step in the R programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Largest proper divisor of n step by step in the R programming language
Table of Contents
Problem Statement
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Largest proper divisor of n step by step in the R programming language
Source code in the r programming language
largest_proper_divisor <- function(n){
if(n == 1) return(1)
lpd = 1
for(i in seq(1, n-1, 1)){
if(n %% i == 0)
lpd = i
}
message(paste0("The largest proper divisor of ", n, " is ", lpd))
return(lpd)
}
#Verify
for (i in 1:100){ #about 10 seconds to calculate until 10000
largest_proper_divisor(i)
}
You may also check:How to resolve the algorithm Last Friday of each month step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Animate a pendulum step by step in the Racket programming language
You may also check:How to resolve the algorithm Create a file on magnetic tape step by step in the Tcl programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Binary Lambda Calculus programming language
You may also check:How to resolve the algorithm Multiplicative order step by step in the Julia programming language