Calculating bit score: How do you find lambda and K?
NCBI BLAST uses tables of pre-computed values for lambda/K for gapped protein and nucleotide comparison and their values depend on the amino acid substitution matrix or the substitution scores + gap penalties.

You can find these tables (from line 589 for blastn) in the file c++/src/algo/blast/core/blast_stat.c from the blast source package.