mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Programming (https://www.mersenneforum.org/forumdisplay.php?f=29)
-   -   Request for an equation. (https://www.mersenneforum.org/showthread.php?t=3087)

Logic 2004-09-19 18:56

Request for an equation.
 
Let me start off by saying, I am terrible at math. I'm not even sure if I know how to explain this for you to understand, but here goes.

I am trying to obtain an equation for series of numbers, with a repeating pattern.
[list][*]The numbers must be greater or equal to [I]n[/I].[*]The first series of numbers, must compose of [I]n[/I] whole numbers after [I]n[/I].[*]After the first, and each series of numbers, [I]n[/I] numbers must be excluded, followed by [I]n[/I] series of numbers, and so on..[/list]
ex.

[I]n[/I] = 4

would result in...

4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23....

[I]n[/I] = 2

2, 3, 6, 7, 10, 11...

Thanks a lot in advance.

marc 2004-09-19 21:26

f(n,x) = n + 2*n*floor(x/n) + x%n

where n is your n and x is the xth number and x=0 is the first.

eg. f(4,0) = 4, f(2,2) = 6


All times are UTC. The time now is 04:23.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.