Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:18:09+00:00 2026-06-10T18:18:09+00:00

I have this recurrence formula: P(n) = ( P(n-1) + 2^(n/2) ) % (X)

  • 0

I have this recurrence formula:

   P(n) = ( P(n-1) + 2^(n/2) ) % (X)
   s.t. P(1) = 2;

where n/2 is computer integer division i.e. floor of x/2

Since i am taking mod X, this relation should repeat at least with in X outputs.

but it can start repeating before that.

How to find this value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:18:10+00:00Added an answer on June 10, 2026 at 6:18 pm

    It needn’t repeat within x terms, consider x = 3:

    P(1)  = 2
    P(2)  = (P(1)  + 2^(2/2))  % 3 = 4 % 3        = 1
    P(3)  = (P(2)  + 2^(3/2))  % 3 = (1 + 2) % 3  = 0
    P(4)  = (P(3)  + 2^(4/2))  % 3 = 4 % 3        = 1
    P(5)  = (P(4)  + 2^(5/2))  % 3 = (1 + 4) % 3  = 2
    P(6)  = (P(5)  + 2^(6/2))  % 3 = (2 + 8) % 3  = 1
    P(7)  = (P(6)  + 2^(7/2))  % 3 = (1 + 8) % 3  = 0
    P(8)  = (P(7)  + 2^(8/2))  % 3 = 16 % 3       = 1
    P(9)  = (P(8)  + 2^(9/2))  % 3 = (1 + 16) % 3 = 2
    P(10) = (P(9)  + 2^(10/2)) % 3 = (2 + 32) % 3 = 1
    P(11) = (P(10) + 2^(11/2)) % 3 = (1 + 32) % 3 = 0
    P(12) = (P(11) + 2^(12/2)) % 3 = (0 + 64) % 3 = 1
    

    and you see that the period is 4.

    Generally (suppose X is odd, it’s a bit more involved for even X), let k be the period of 2 modulo X, i.e. k > 0, 2^k % X = 1, and k is minimal with these properties (see below).

    Consider all arithmetic modulo X. Then

               n
    P(n) = 2 + ∑ 2^(j/2)
              j=2
    

    It is easier to see when we separately consider odd and even n:

                       m           m
    P(2*m+1) = 2 + 2 * ∑ 2^i = 2 * ∑ 2^i = 2*(2^(m+1) - 1) = 2^((n+2)/2) + 2^((n+1)/2) - 2
                      i=1         i=0
    

    since each 2^j appears twice, for j = 2*i and j = 2*i+1. For even n = 2*m, there’s one summand 2^m missing, so

    P(2*m) = 2^(m+1) + 2^m - 2 = 2^((n+2)/2) + 2^((n+1)/2) - 2
    

    and we see that the length of the period is 2*k, since the changing parts 2^((n+1)/2) and 2^((n+2)/2) have that period. The period immediately begins, there is no pre-period part (there can be a pre-period for even X).

    Now k <= φ(X) by Euler’s generalisation of Fermat’s theorem, so the period is at most 2 * φ(X).
    (φ is Euler’s totient function, i.e. φ(n) is the number of integers 1 <= k <= n with gcd(n,k) = 1.)


    What makes it possible that the period is longer than X is that P(n+1) is not completely determined by P(n), the value of n also plays a role in determining P(n+1), in this case the dependence is simple, each power of 2 being used twice in succession doubles the period of the pure powers of 2.

    Consider the sequence a[k] = (2^k) % X for odd X > 1. It has the simple recurrence

    a[0] = 1
    a[k+1] = (2 * a[k]) % X
    

    so each value completely determines the next, thus the entire following part of the sequence. (Since X is assumed odd, it also determines the previous value [if k > 0] and thus the entire previous part of the sequence. With H = (X+1)/2, we have a[k-1] = (H * a[k]) % X.)

    Hence if the sequence assumes one value twice (and since there are only X possible values, that must happen within the first X+1 values), at indices i and j = i+p > i, say, the sequence repeats and we have a[k+p] = a[k] for all k >= i. For odd X, we can go back in the sequence, therefore a[k+p] = a[k] also holds for 0 <= k < i. Thus the first value that occurs twice in the sequence is a[0] = 1.

    Let p be the smallest positive integer with a[p] = 1. Then p is the length of the smallest period of the sequence a, and a[k] = 1 if and only if k is a multiple of p, thus the set of periods of a is the set of multiples of p. Euler’s theorem says that a[φ(X)] = 1, from that we can conclude that p is a divisor of φ(X), in particular p <= φ(X) < X.

    Now back to the original sequence.

    P(n) = 2 + a[1] + a[1] + a[2] + a[2] + ... + a[n/2]
         = a[0] + a[0] + a[1] + a[1] + a[2] + a[2] + ... + a[n/2]
    

    Since each a[k] is used twice in succession, it is natural to examine the subsequences for even and odd indices separately,

    E[m] = P(2*m)
    O[m] = P(2*m+1)
    

    then the transition from one value to the next is more regular. For the even indices we find

    E[m+1] = E[m] + a[m] + a[m+1] = E[m] + 3*a[m]
    

    and for the odd indices

    O[m+1] = O[m] + a[m+1] + a[m+1] = O[m] + 2*a[m+1]
    

    Now if we ignore the modulus for the moment, both E and O are geometric sums, so there’s an easy closed formula for the terms. They have been given above (in slightly different form),

    E[m] = 3 * 2^m - 2     = 3 * a[m] - 2
    O[m] = 2 * 2^(m+1) - 2 = 2 * a[m+1] - 2 = a[m+2] - 2
    

    So we see that O has the same (minimal) period as a, namely p, and E also has that period. Unless maybe if X is divisible by 3, that is also the minimal (positive) period of E (if X is divisible by 3, the minimal positive period of E could be a proper divisor of p, for X = 3 e.g., E is constant).

    Thus we see that 2*p is a period of the sequence P obtained by interlacing E and O.

    It remains to be seen that 2*p is the minimal positive period of P. Let m be the minimal positive period. Then m is a divisor of 2*p.

    Suppose m were odd, m = 2*j+1. Then

    P(1) = P(m+1) = P(2*m+1)
    P(2) = P(m+2) = P(2*m+2)
    

    and consequently

    P(2) - P(1) = P(m+2) - P(m+1) = P(2*m+2) - P(2*m+1)
    

    But P(2) - P(1) = a[1] and

    P(m+2)   - P(m+1)   = a[(m+2)/2]            = a[j+1]
    P(2*m+2) - P(2*m+1) = a[(2*m+2)/2] = a[m+1] = a[2*j+2]
    

    So we must have a[1] = a[j+1], hence j is a period of a, and a[j+1] = a[2*j+2], hence j+1 is a period of a too. But that means that 1 is a period of a, which implies X = 1, a contradiction.

    Therefore m is even, m = 2*j. But then j is a period of O (and of E), thus a multiple of p. On the other hand, m <= 2*p implies j <= p, and the only (positive) multiple of p satisfying that inequality is p itself, hence j = p, m = 2*p.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to find the recurrence equation from this algorithm: ALGO(n) if n <=
I have been challenged to find the general term or the recurrence relation for
I have been writing a program for the following recurrence relation: An = 5An-1
I have this Json returned from controller : public ActionResult VerifyApp(string recurrence) { List<foo>
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have this application where I implement the ActionBar Fragment interface. Underlying the interface,
I have this form, in which i need to populate a combo box with
I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.