
法一
用 for 循环计算序列和。
法二
使用等差数列求和公式。
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
int main()
{
  LL res = 0;
  for (int i = 1; i <= 20230408; ++ i )
    res += i;
  
  cout << res << endl;
  return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
int main()
{
  int n = 20230408;
  LL res = (LL)(1 + n) * n / 2;
  
  cout << res << endl;
  return 0;
}
【在线测评】




















