Gain formula in Gens I-IV

as for Gen V

Unlike the great variation in formulas among the six experience groups, there is only a single formula used to determine how much experience a Pokémon will gain from battle, to the right. In this formula:

a is equal to 1 if the fainted Pokémon is wild, and 1.5 if the fainted Pokémon is owned by a Trainer.

t is equal to 1 if the winning Pokémon's OT is its current owner, 1.5 if the Pokémon was gained in a domestic trade, and 1.7 if the Pokémon was gained in an international trade.

b is the base experience yield of the fainted Pokémon's species, listed here.

e is equal to 1.5 if the winning Pokémon is holding a Lucky Egg, and 1 otherwise.

L is the level of the fainted Pokémon.

In Generation V, Lp is the level of the victorious Pokémon.

s is the number of Pokémon that participated in the battle and have not fainted. If any Pokémon in the party is holding an Exp. Share, s is equal to 2, and for the rest of the Pokémon, s is equal to twice the number of Pokémon that participated instead.

If more than one Pokémon is holding an Exp. Share, s is equal to twice the number of Pokémon holding the Exp. Share for each Pokémon holding one.

p is equal to 1 if no Exp. Point Power is active, or else equal to the following depending on the power: Power ↓: 0.5; Power ↓↓: 0.66; Power ↓↓↓: 0.8; Power ↑: 1.2; Power ↑↑: 1.5; Power ↑↑↑, Power S, Power MAX: 2.

In Generation V, the experience gain formula was revamped. The constant divisor of 7 was changed to 5, and a factor was added that took the battling Pokémon's level into account.

Also, a constant of 1 was added to each battle, presumably to prevent a defeated Pokémon from yielding 0 experience due to a very low ratio between levels.

http://bulbapedia.bulbagarden.net/wiki/Exp#Gain_formula