UVaLive 7359 Sum Kind Of Problem (数学,水题)

题意:给定一个n,求前 n 个正整数,正奇数,正偶数之和。

析:没什么好说的,用前 n 项和公式即可。

代码如下:

#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 inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 5;
const int mod = 1e9 + 7;
const 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, int 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;
}

  

上一篇:Codeforces Round #271 (Div. 2)题解【ABCDEF】


下一篇:Android:控件ListView列表项与适配器结合使用