Editorial -TAXPAID

Problem link Link
Author-Rishabh Verma
Tester - Manas Rawat
Editorialist - Rishabh Verma

Difficulty :
Medium

Problem

In question , you have given N houses who give tax for M month. And they pay some extra tax C . You have to calculate this extra tax for M months .

Explanation

If you see there is no use of the given tax . Here if we calculate sum of natural number from 1 to M and multiply it by total number of houses that is N our job is done .
Now all we need to calculate N*( M (M-1) / 2) and take modulo with 10e9+7 .
Because the range is larger we calculate inverse modulo of 2 . and solve as given above

MY Solution

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;

ll inv(ll a, ll b = mod - 2) {
	ll res = 1;
	for ( ; b; b >>= 1) {
		if (b & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
	}
	return res;
}

int main() {
    int t;  cin >> t;
	while (t--) {
		ll n, m;
	    cin >> n >> m;
    	for (int i = 0; i < n; i++) {
    		int k;  cin >> k;
    	}
    	m %= mod;
    	ll res = m * (m + 1LL) % mod * inv(2) % mod;
    	res = res * n % mod;
    	cout << res << "\n";
	}
	return 0;
}