I have a stupid doubt if in question we have given range of values upto 10^18 but the answer is accepted to be MODULO 10^9 + 7.

Then i have two choices:

- At each step i should take MODULO, despite the fact that number can be stored in long long int range.(shown by fun1)
- I should take MODULO only where the result is excepted to overflow range of data type.(shown by fun2)

which approach is correct and why ?

ll:long long int

ex:

void fun1(ll a,ll b)

{

a=a%M;

b=b%M;

ll c=(a+b)%M;

ll d=(c*a)%M;

cout<<d<<endl;

}

void fun2(ll a,ll b)

{

ll c=(a+b)%M;

ll d=(c*a)%M;

cout<<d<<endl;

}