Wuhan University of Science and Technology acm:1001:0 starting point algorithm 34--continue to seek polynomial

Source: Internet
Author: User

Problem Description

Enter a 1 positive integer n,
Calculation 1+ (1+2) + (1+2+3) +...+ (1+2+3+...+n)

Input

Input positive integer n (multiple sets of data)

Output

Output 1+ (1+2) + (1+2+3) +...+ (1+2+3+...+n) value (one row per group of data)

Sample Input

2

Sample Output

4

1#include <iostream>2 3 using namespacestd;4 5 intMain ()6 7 {8 9          intn,t;Ten  One          Longsum; A  -           while(cin>>N) -  the          { -  -sum=0; -  +t=0; -  +                     for(intI=1; i<=n;i++) A  at                    { -  -t+=i; -  -sum+=T; -  in                    } -  tocout<<sum<<Endl; +  -          } the  *          return 1; $ Panax Notoginseng          -  the          +  A}

Other code

1#include <stdio.h>2 intMain ()3 {4     intn,sum,i;5      while(SCANF ("%d", &n)! =EOF)6     {7          for(i=1, sum=0; i<=n;i++)8sum+= (n-i+1)*i;9printf"%d\n", sum);Ten     } One     return 0; A}

Wuhan University of Science and Technology acm:1001:0 starting point algorithm 34--continue to seek polynomial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.