Test instructions: Given an n, the sum of the first n positive integers, positive and odd, and even.
Analysis: There is nothing to say, using the first n and the formula can be.
The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < Stack>using namespace Std;typedef Long Long ll;typedef pair<int, int> p;const int INF = 0x3f3f3f3f;const double I NF = 0x3f3f3f3f3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = ten + 5;const int mod = 1e9 + 7;c Onst char *mark = "+-*"; const int dr[] = {-1, 0, 1, 0};const int dc[] = {0, 1, 0, -1};int N, m;inline bool is_in (int R, in T c) {return R >= 0 && r < n && C >= 0 && C < m;} int main () {int T; cin >> T; while (t--) {int kase; scanf ("%d%d", &kase, &n); ll ans1 = (LL) n (n+1)/2; ll ans2 = (LL) n (2LL + 2ll*n)/2; LL ans3 = (LL) n * (2ll*n)/2; printf ("%d%lld%lld%lld\n", Kase, Ans1, ANS3, ANS2); } return 0;}
LA 7359 Sum Kind of problem (maths, water problem)