A common painkiller used by millions could boost memory and intelligence, a study has found.