how to find twin prime less than 100 in R using search.prime(), loop and cat

I want to know how to find twin prime less than 200 in R by using search.prime / loop / cat prime plz let me know this problem

Firstly, this sounds like a homework assignment, so do be aware of our homework policy, FAQ: Homework Policy

This kind of thing is pretty straightforward to do with R. Assuming this a homework question, could you let us know what you've attempted to do already, what issues you're having? Ideally, pose these with a reprex.

Also, I am not familiar with search.prime or cat prime, in either base-R or an R package on CRAN after a quick search. Could you set these up?

1 Like

Also cross posted with no explanation why the suggested solution didn't work.

library(RcppAlgos)

twin200 <- primeSieve(200)
i <- which(diff(twin200) == 2)
cbind(twin1 = twin200[i], twin2 = twin200[i + 1L])
#>       twin1 twin2
#>  [1,]     3     5
#>  [2,]     5     7
#>  [3,]    11    13
#>  [4,]    17    19
#>  [5,]    29    31
#>  [6,]    41    43
#>  [7,]    59    61
#>  [8,]    71    73
#>  [9,]   101   103
#> [10,]   107   109
#> [11,]   137   139
#> [12,]   149   151
#> [13,]   179   181
#> [14,]   191   193
#> [15,]   197   199

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.