(Genesis 41:16) "And Joseph answered Pharaoh, saying: it is not in me; God will answer for Pharaoh's welfare." He ascribed the greatness to its true Owner. (Genesis 41:26) "The seven good cows are seven years." Rabbi Yehudah says: there were fourteen years, for so Pharaoh saw. Rav Nachman says: twenty-eight years, for Pharaoh saw and told Joseph (and Joseph repeated and told Pharaoh). The Rabbis say: forty-two, for Pharaoh saw and told Joseph ("in my dream, behold") and Joseph repeated and told Pharaoh. Rabbi Yose ben Rabbi Chanina said: the famine lasted two years; once our father Jacob went down to Egypt, the famine ended. And when did it return? In the days of Ezekiel. This is what is written (Ezekiel 29:12) "And I will make the land of Egypt a desolation in the midst of desolate lands (forty years), and its cities shall be a desolation in the midst of ruined cities [forty years]."
Seven Good Cows Are Seven Years and the End of Famine
Yalkut Shimoni on Torah 147:5
(בראשית מא טז) וַיַּעַן יוֹסֵף אֶת פַּרְעֹה לֵאמֹר בִּלְעָדָי אֱלֹהִים יַעֲנֶה אֶת שְׁלוֹם פַּרְעֹה. תָּלָה גְּדוּלָה בִּבְעָלֶיהָ. (בראשית מא כו) שֶׁבַע פָּרֹת הַטֹּבֹת שֶׁבַע שָׁנִים הֵנָּה, רַבִּי יְהוּדָה אוֹמֵר, אַרְבַּע עֶשְׂרֵה שָׁנָה הָיוּ שֶׁכֵּן פַּרְעֹה רוֹאֶה רַב נַחְמָן אוֹמֵר, עֶשְׂרִים וּשְׁמוֹנֶה שָׁנָה שֶׁכֵּן פַּרְעֹה רוֹאֶה וְאוֹמֵר לְיוֹסֵף (וְיוֹסֵף חוֹזֵר וְאוֹמֵר לְפַרְעֹה). רַבָּנָן אַמְרִין, אַרְבָּעִים וּשְׁתַּיִם שֶׁכֵּן פַּרְעֹה רוֹאֶה וְאוֹמֵר לְיוֹסֵף (בַּחֲלֹמִי וְהִנְנִי) וְחוֹזֵר יוֹסֵף וְאוֹמֵר לְפַרְעֹה אָמַר רַבִּי יוֹסֵי בֶּן רַבִּי חֲנִינָא, שְׁתֵּי שָׁנִים עָשָׂה רָעָב, כֵּיוָן שֶׁיָּרַד אָבִינוּ יַעֲקֹב לְמִצְרַיִם כִּלָּה אֶת הָרָעָב, וְאֵימָתַי חָזְרוּ, בִּימֵי יְחֶזְקֵאל. הֲדָא הוּא דִכְתִיב (יחזקאל כט, יב) "וְנָתַתִּי אֶת אֶרֶץ מִצְרַיִם שְׁמָמָה בְּתוֹךְ אֲרָצוֹת נְשַׁמּוֹת (אַרְבָּעִים שָׁנָה) וְעָרֶיהָ בְּתוֹךְ עָרִים מָחֳרָבוֹת [תִּהְיֶיןָ שְׁמָמָה] אַרְבָּעִים שָׁנָה".