Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <numeric>
- using namespace std;
- long long n, m, sum, type = 0;
- void read()
- {
- cin >> n >> m;
- }
- long long Cal (long long a, long long b)
- {
- return (a + b)*(b - a + 1)/2;
- }
- void solve()
- {
- if (n > 1)
- {
- sum += n - 1;
- }
- if (m > 2)
- {
- sum += m - 2;
- }
- --n;
- m -= 2;
- if (n > 0 && m > 0)
- {
- if (n <= m)
- {
- int t = n - 1;
- sum += Cal(1, t) + Cal (m - t, m - 1);
- }
- else
- {
- int t = m;
- sum += Cal(n - t, n - 1) + Cal (1, m - 1);
- }
- }
- cout << sum;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- read();
- solve();
- }
Add Comment
Please, Sign In to add comment