Lots of problems:
65535 is 2^16 or 2 bytes where as a long is generally 4 bytes long or 2^32. You could change your program to use shorts which are generally 2 bytes long
Some compilers now provide 2^64 for longs (a long must be at least 2^32 but can be larger). Similar rules apply to shorts.
You are using signed long which means one bit is used to denote a sign so even if you were using shorts entering 65535 would actually be a value of -1 (so change to use unsigned shorts)
if you add two unsigned shorts together and put the answer into a short the total can never be more than 65535 because a short can't denote that large a value.