There are 365 days in a year and so, total number of outcomes possible are 365.
However, for them to have different birthdays i.e. if Ram has his birthday on a given date, then Shyam can have his birthday on any of the remaining 364 days except that day. So, the favourable outcomes for Shyam are 364 but for Ram, all of the 365 days are possible.
P(different birthdays) = P(Ram's birthday) * P(Shaym's birthday)
P(different birthdays) = 365/365 * 364/365 = 364/365
P(same birthdays) = 1 - P(different birthdays)
P(same birthdays) = 1- 364/365
P(same birthdays) = 1/365