HDUOJ 1001 Sum Problem

 1 #include <iostream>
 2
 3 using namespace std;
 4 long long sum(long long n);
 5
 6 int main()
 7 {
 8     long long n;
 9     while(cin >> n)
10         cout << sum(n) << endl << endl;
11     return 0;
12 }
13
14 long long sum(long long n)
15 {
16     return (1 + n) * n / 2;
17 }
时间: 2024-12-25 01:26:56

HDUOJ 1001 Sum Problem的相关文章

HDU 1001 Sum Problem

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. InputThe input will consist of a series of integers n, one integer per line. OutputFor each ca

HDU 1001 Sum Problem C/C++

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line. Output For each

水题/hdu 1001 Sum Problem

题意 给出一个数n,求1+2+??+n=? 分析 注意多case Accepted Code 1 /* 2 PROBLEM:hdu1001 3 AUTHER:NicoleLam 4 MEMO:水题 5 */ 6 7 #include<cstdio> 8 9 int main() 10 { 11 int n; 12 while (scanf("%d",&n)!=EOF) 13 { 14 int s=0; 15 for (int i=1;i<=n;i++) s+=

杭电1001 Sum Problem

先看题目 这题,按照题目意思,我理解,应该是先是输入,每组输入一行,然后是对应的各个输出,输出间多加一条空白行,但是问题是怎么就知道他已经输入完毕了,下面应该显示输出.受题目输入输出事例误解.后来改为了一行输出,紧接着就是这行的输出,然后再是输入,输出,这样交替着. #include<iostream> using namespace std; int Sum(int); int main(){ int inputA; while(cin>>inputA) { cout<&l

Maxmum subsequence sum problem

We have a lot of ways to solve the maximum subsequence sum problem, but different ways take different time. 1.Brute-force algorithm int maxSubSum1(const vector<int> &a) { int maxSum=0; for(int i=0;i<a.size();i++) for(int j=i;j<a.size();j++

hdu 2576 Another Sum Problem

题目大意:求前n项和的前n项和. 数学推导题,f(n)=n*(n+1)*(n+2)/6 推导思路如下: #include"cstdio" #include"cstring" #include"cmath" #include"cstdlib" #include"iostream" #include"algorithm" #include"queue" using nam

NYOJ 927 The partial sum problem 【DFS】+【剪枝】

The partial sum problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N integers and the sum of them is equal to K. 输入 There are mul

nyoj927 The partial sum problem(dfs)

The partial sum problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N integers and the sum of them is equal to K. 输入 There are multi

NYOJ-927 The partial sum problem

The partial sum problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N integers and the sum of them is equal to K. 输入 There are multi