Files
python/TangDou/ShuLun/SL_18.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

17 lines
383 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
//给出等差数列的前两项分别是a1,a2,问第n项是多少
int x, y, n;
int main() {
cin >> x >> y >> n;
int z = y - x;
if (n == 1) cout << x << endl;
if (n == 2) cout << y << endl;
if (n >= 3) {
for (int i = 3; i <= n; i++)y += z;
cout << x << endl;
}
return 0;
}