Time-dependent density functional theory scheme for efficient calculations of dynamic (hyper)polarizabilities.