Comet OJ c1023

c1023

更好的博客阅读http://cconstantine.xyz/2020/03/10/c1023/

这道题教会了我们观察。

理解题意后得到要求我们输出

\[ 1+2+3+4+\cdots +n+n-1+\cdots + 1 \]

自然想起等差数列和的公式

\[ S = \frac{(1+n)n}{2} \]

自然得到

\[ ans = (n+1)n-n \]

下附代码

#include <iostream>
#include <cstdio>

using std::cin;using std::cout;using std::endl;using std::cerr;

int main(){
    long long N;

    cin>>N;

    cout<<(N+1)*N-N;
    
    return 0;
}

原题地址https://www.cometoj.com/problem/1023

posted @ 2020-02-29 18:01  CConstantine  阅读(137)  评论(0)    收藏  举报