ACM看不懂题

[复制链接]
查看11 | 回复2 | 2008-8-4 14:26:13 | 显示全部楼层 |阅读模式
一道题
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 case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1
100
Sample Output
1
5050
输出格式中output SUM(n) in one line是什么意思?
我英语好烂,大侠帮忙
Sum(n)是指哪个?
我这么编可以吗?
main()
{
long a,b;
while (scanf ("%ld %ld",&b,&a)!=EOF)

printf ("%ld\n\n%ld\n",b,(a+b)*(a-b+1)/2);
}

回复

使用道具 举报

千问 | 2008-8-4 14:26:13 | 显示全部楼层
就是让你求从1加到n,一个输出结果一行,结果之间隔一行
回复

使用道具 举报

千问 | 2008-8-4 14:26:13 | 显示全部楼层
就是: 在一行上输出Sum(n)PS://索性代码也贴了哈//就是输出前n项和,当然要注意下格式...#includeusing namespace std;int main(){
for (long long n;cin>>n;)
cout<<n*(n+1)/2<<endl<<endl
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行