The number of electrons in each orbital is double an odd number (the Pauli exclusion principleprincilel states electrons can be in the same energy only if of opposite spin, so there can be two otherwise identical electron energy states [which can be separated in an EM field]).
- s (sharp spectral lines): 2 (twice 1)
- p (principleprincipal spectral lines): 6 (twice 3)
- d (diffuse spectral line): 10 (twice 5)
- f (finefine, or "fundamental", spectral lines): 14 (twice 7)
Using that information, and the fact that the first row has only s electrons, second row s & p, usw., you should be able to calculate the first few rows easily. However, rules become much more complex for transition metals and heavier elements, where an outer shell may be added before all inner orbitals are filled.
Primary valence for the first few rows is simply the number of electrons needed to either complete the current shell (e.g. oxygen is two e- short), or revert to the previous complete, noble gas, configuration (e.g. Na minus one e- is neon). Again, there are complications, such as transition metals with multiple valences, fluorine reacting with some noble gases, usw.