题解 | 等差数列
#include <iostream> using namespace std; int main() { int n; cin >> n; int begin = 2; int end = 3*n-1; cout << (begin + end)*n/2;//(首项+末项)*项数/2 } // 64 位输出请用 printf("%lld")
#include <iostream> using namespace std; int main() { int n; cin >> n; int begin = 2; int end = 3*n-1; cout << (begin + end)*n/2;//(首项+末项)*项数/2 } // 64 位输出请用 printf("%lld")
相关推荐