Codeforces 931A Friends Meeting

#define _CRT_SECURE_NO_WARNINGS
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int n, m;
int ans;

int main() {
	scanf("%d %d", &n, &m);
	int dif = abs(n - m);
	if (dif % 2 == 0) {
		int cnt = dif / 2;
		for (int i = 1;i <= cnt;++i) {
			ans += (i * 2);
		}
	}
	else {
		int cnt = dif / 2;
		for (int i = 1;i <= cnt;++i) {
			ans += (i * 2);
		}
		ans += (cnt + 1);
	}
	printf("%d\n", ans);
	//system("pause");
	return 0;
}

 

你可能感兴趣的:(ACM)