I was trying to solve a question on codeforces . I have to give input
1000000000 1000000000 1
to this code
#include <iostream>
using namespace std;
int main()
{
long n,m,a;
cin >> n >> m >>a ;
long b,c;
b = (n%a==0)?(n/a):((n/a)+1);
c = (m%a==0)?(m/a):((m/a)+1);
unsigned long long d ;
d = b*c ;
cout<<d;
But it gave me error
Diagnostics detected issues [cpp.clang++-diagnose]: p71.cpp:12:5: runtime error: signed
integer overflow: 1000000000 * 1000000000 cannot be represented in type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior p71.cpp:12:5 in
Then I got to know that I should add ULL suffix on a numeric literal. But how should I use ULL in this type of code;
You cannot use ULL after variables. It is a suffix for integer literals. You should use ULL after those integer literals that you wish to be of type
unsigned long longbecause that's what the suffix does.All integer types have an upper (as well as lower) limit. Exact maximum values are specific to each system although the language standard does specify a lower bound as a requirement. If you know that a calculation will exceed the limits of a particular type, then you must use a larger type. If you don't know maximum result of a calculation or you know that it would exceed the limit of the largest integer type, then you must change strategy and not use plain integer types: Instead, you would need to use arbitrary precision arithmetic.