Click here to Skip to main content
15,895,084 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Classic computer science problems Pin
Fueled By Decaff25-Apr-19 21:16
Fueled By Decaff25-Apr-19 21:16 
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 2:14
mvaraddevus26-Apr-19 2:14 
GeneralRe: Classic computer science problems Pin
Dominic Burford25-Apr-19 22:01
professionalDominic Burford25-Apr-19 22:01 
GeneralRe: Classic computer science problems Pin
pkfox26-Apr-19 0:32
professionalpkfox26-Apr-19 0:32 
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 2:15
mvaraddevus26-Apr-19 2:15 
GeneralRe: Classic computer science problems Pin
harold aptroot26-Apr-19 4:34
harold aptroot26-Apr-19 4:34 
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 5:34
mvaraddevus26-Apr-19 5:34 
GeneralRe: Classic computer science problems Pin
harold aptroot26-Apr-19 6:09
harold aptroot26-Apr-19 6:09 
OH I like big fibs and I cannot lie, here's a nice trick if you don't mind some BigInteger hackery,

Take some nice prime p such that p ≡ 3 mod 4 (this congruence is not strictly required but makes the next part easier). For example p = 45427892858481394071686190649738831656137145778469793250959984709250004157335359

Then calculate the square root of 5 = BigInteger.ModPow(5, (p + 1) / 4, p) (this simple formula works before p was chosen with p ≡ 3 mod 4).

Calculate a couple of fancy constants,
C#
BigInteger half = BigInteger.ModPow(2, p - 2, p);
BigInteger phi = (1 + sqrt5) * half % p;
BigInteger psi = (1 + p - sqrt5) * half % p;
BigInteger invsqrt5 = BigInteger.ModPow(sqrt5, p - 2, p);
And then you can use the modular arithmetic version of Binet's Formula,
C#
BigInteger fib(int n)
{
    return (BigInteger.ModPow(phi, n, p) - BigInteger.ModPow(psi, n, p) + p) * invsqrt5 % p;
}
Good for n up to around 380 or so, you can use a bigger prime if you want to go higher.

This is more or less a joke of course, if you wanted efficient fibonacci calculations you could also use the optimized version (less redundancy) of matrix powering.
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 7:30
mvaraddevus26-Apr-19 7:30 
GeneralSmartXML Pin
Bassam Abdul-Baki25-Apr-19 8:05
professionalBassam Abdul-Baki25-Apr-19 8:05 
GeneralRe: SmartXML Pin
Mark_Wallace25-Apr-19 8:07
Mark_Wallace25-Apr-19 8:07 
GeneralRe: SmartXML Pin
Bassam Abdul-Baki25-Apr-19 9:13
professionalBassam Abdul-Baki25-Apr-19 9:13 
GeneralRe: SmartXML Pin
Marc Clifton25-Apr-19 8:54
mvaMarc Clifton25-Apr-19 8:54 
GeneralRe: SmartXML Pin
Bassam Abdul-Baki25-Apr-19 9:13
professionalBassam Abdul-Baki25-Apr-19 9:13 
GeneralRe: SmartXML Pin
Mark_Wallace25-Apr-19 9:55
Mark_Wallace25-Apr-19 9:55 
GeneralRe: SmartXML Pin
Bassam Abdul-Baki25-Apr-19 12:19
professionalBassam Abdul-Baki25-Apr-19 12:19 
GeneralRe: SmartXML Pin
Marc Clifton26-Apr-19 2:08
mvaMarc Clifton26-Apr-19 2:08 
GeneralRe: SmartXML Pin
Brisingr Aerowing25-Apr-19 11:45
professionalBrisingr Aerowing25-Apr-19 11:45 
GeneralRe: SmartXML Pin
MarkTJohnson26-Apr-19 3:01
professionalMarkTJohnson26-Apr-19 3:01 
GeneralRe: SmartXML Pin
kalberts26-Apr-19 7:33
kalberts26-Apr-19 7:33 
GeneralSpace, the final frontier Pin
RickZeeland25-Apr-19 6:49
mveRickZeeland25-Apr-19 6:49 
GeneralRe: Space, the final frontier Pin
Mark_Wallace25-Apr-19 8:05
Mark_Wallace25-Apr-19 8:05 
GeneralRe: Space, the final frontier Pin
dandy7225-Apr-19 9:22
dandy7225-Apr-19 9:22 
GeneralRe: Space, the final frontier Pin
David O'Neil25-Apr-19 15:23
professionalDavid O'Neil25-Apr-19 15:23 
GeneralRe: Space, the final frontier Pin
dandy7226-Apr-19 10:03
dandy7226-Apr-19 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.