zoukankan      html  css  js  c++  java
  • 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
    ", kase, ans1, ans3, ans2);
        }
        return 0;
    }
    

      

  • 相关阅读:
    androidlayout_weight的使用
    软件开发中的真理.
    apk,task,android:process与android:sharedUserId的区别
    WIFI连接
    go simple web server
    echo命令
    shell if
    linux grep命令(包括正则)
    make命令和Makefile文件
    linux中grep命令的用法
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5774230.html
Copyright © 2011-2022 走看看