-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp26.R
More file actions
36 lines (31 loc) · 818 Bytes
/
Copy pathp26.R
File metadata and controls
36 lines (31 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# [1] 983
# user system elapsed
# 0.084 0.012 0.095
#only look at primes, composites will have the same number of recurring digits
# number of recuring decimals cannot be more than the number-1. Count backwards from 1000
main <- function(){
pmt <- proc.time()
library(numbers)
p <- sort(Primes(1000), decreasing = TRUE)
maxrd <- 0
for(i in p){
rd <- recurringDigits(i)
if(rd>maxrd){
maxrd <- rd
maxPrime <- i
}
if(maxrd>i){break}
}
print(maxPrime)
print(proc.time()-pmt)
}
recurringDigits <- function(d){
x <- 1
remainders <- c(x)
repeat{
x <- (x*10)%%d
if(x %in% remainders){break}
remainders <- c(remainders,x)
}
return(length(remainders) - which(remainders==x) + 1)
}