文章目录
- AcWing 719. 连续奇数的和 2
- AC代码
AcWing 719. 连续奇数的和 2
本题链接:AcWing 719. 连续奇数的和 2
本博客给出本题截图:
AC代码
代码:
#include <iostream> using namespace std; int main() { int n, x, y, num; cin >> n; for (int i = 0; i < n; i ++ ) { num = 0; cin >> x >> y; if (x > y) { int t = x; x = y; y = t; } for(int j = x + 1; j < y; j ++ ) if (j % 2 == 1 || j % 2 == -1) num += j; cout << num << endl; } return 0; }