Variable stars in large magellanic cloud globular clusters. II. NGC 1786