Skip to main content
copy editing
Source Link
Stephen Rauch
  • 4.3k
  • 12
  • 24
  • 36

sorrySorry, I giveam giving no code (I typeam on a phone and I don't know pythonPython), but be aware that if m^2 is way lower than n, you could use the fact that your function gets periodical with a period maximally m^2 (as both a[-1] and a[-2] can gain m different values).

You could test in your for loop if/when you reached your period (if a[-2]==0 and a[-1]==1) and if so, variable i would indicate your period. Then you could simply grab a[n%(i-2)] as the answer, if I am not mistaken.

Btw.By the way, shouldn't the forfor loop range begin with 2?

sorry, I give no code (I type on a phone and don't know python), but be aware that if m^2 is way lower than n, you could use the fact that your function gets periodical with a period maximally m^2 (as both a[-1] and a[-2] can gain m different values).

You could test in your for loop if/when you reached your period (if a[-2]==0 and a[-1]==1) and if so, variable i would indicate your period. Then you could simply grab a[n%(i-2)] as the answer, if I am not mistaken.

Btw. shouldn't the for loop range begin with 2?

Sorry, I am giving no code (I am on a phone and I don't know Python), but be aware that if m^2 is way lower than n, you could use the fact that your function gets periodical with a period maximally m^2 (as both a[-1] and a[-2] can gain m different values).

You could test in your for loop if/when you reached your period (if a[-2]==0 and a[-1]==1) and if so, variable i would indicate your period. Then you could simply grab a[n%(i-2)] as the answer, if I am not mistaken.

By the way, shouldn't the for loop range begin with 2?

sorry, I give no code (I type on a phone and don't know python), but be aware that if m^2m^2 is way lower than nn, you could use the fact that your function gets periodical with a period maximally m^2m^2 (as both a[-1]a[-1] and a[-2]a[-2] can gain m different values).

You could test in Your foryour for loop if/when you reached your period (if a[-2]==0a[-2]==0 and a[-1]==1a[-1]==1) and if so, variable ii would indicate your period. Then you could simply grab a[n%(i-2)]a[n%(i-2)] as the answer, if I am not mistaken.

Btw. shouldn't the for loop range begin with 2?

sorry, I give no code (I type on a phone and don't know python), but be aware that if m^2 is way lower than n, you could use the fact that your function gets periodical with a period maximally m^2 (as both a[-1] and a[-2] can gain m different values).

You could test in Your for loop if/when you reached your period (if a[-2]==0 and a[-1]==1) and if so, variable i would indicate your period. Then you could simply grab a[n%(i-2)] as the answer, if I am not mistaken.

Btw. shouldn't the for loop range begin with 2?

sorry, I give no code (I type on a phone and don't know python), but be aware that if m^2 is way lower than n, you could use the fact that your function gets periodical with a period maximally m^2 (as both a[-1] and a[-2] can gain m different values).

You could test in your for loop if/when you reached your period (if a[-2]==0 and a[-1]==1) and if so, variable i would indicate your period. Then you could simply grab a[n%(i-2)] as the answer, if I am not mistaken.

Btw. shouldn't the for loop range begin with 2?

Source Link

sorry, I give no code (I type on a phone and don't know python), but be aware that if m^2 is way lower than n, you could use the fact that your function gets periodical with a period maximally m^2 (as both a[-1] and a[-2] can gain m different values).

You could test in Your for loop if/when you reached your period (if a[-2]==0 and a[-1]==1) and if so, variable i would indicate your period. Then you could simply grab a[n%(i-2)] as the answer, if I am not mistaken.

Btw. shouldn't the for loop range begin with 2?