How to find sum of numbers from 0 to n modulus 109 + 7, where n ≤ 1018?
I want to store the result in long long int only and not in array or string. My code results in a run time error.
const unsigned int m = 1000000007;
long long int n;
cin >> n;
long long int s = 0;
for (long long int i = 0; i < n; i++) {
s = ((s % m) + (i % m)) % m;
}
cout << s << endl;