A powerful undersea earthquake that struck off the Indonesian islands of Sumatra and Java has killed four people and damaged hundreds of buildings, the nation’s disaster agency said on Saturday.