Problem: Matthew and Luke both write a genealogy for Jesus, but these are different from one another. Once Matthew and Luke reach David, they diverge from one another rapidly. Matthew has 26 names and Luke has 41 names (between David and Jesus).
Solution: It is not at all uncommon to find genealogies differing in length. The purpose of a genealogy was to show descent, so the Jewish scribe would often skip multiple generations to show the ultimate lineage to a key figure in history. For instance, Aaron’s high priestly genealogy is this way (compare 1 Chron. 6:3-14 with Ezra 7:1-5). Ezra jumps from the 8th name to the 15th name.
Matthew and Luke agree on Jesus’ ultimate ancestors (e.g. David, Abraham, etc.), but they emphasize others in their genealogies because they were writing to different audiences. We can compare their emphases in this way: