I was trying to do some newbie competitive programming problems (because currently i am a newbie :D). I got this strange error with constant and long long division... And watched carefully about tipe conversion problems (can't see any).
I don't understand why such division, gives 1e18 instead of desired result...
#include <iostream>
#define ll long long
#define UPPER (ll)1e18 + 1
ll mult(ll first, ll second)
{
ll div = UPPER / second;
std::cout << UPPER / second << " " << UPPER << std::endl;
if (first > div)
{
return UPPER;
}
return first * second;
}
int main()
{
//51e10
ll first = 510000000000, second = 510000000000;
std::cout << mult(first, second);
}
And the output i get is:
1000000000000000000 1000000000000000001
908560695322214400