#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
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;
}
本文展示了一个使用C++编写的简单程序,该程序通过输入两个整数并计算它们之间的差值来解决问题。程序首先获取两个整数n和m,然后计算它们之间的绝对差,并根据差值是否为偶数来决定最终答案的计算方式。
402

被折叠的 条评论
为什么被折叠?



