fjnu 1943 Gau? in Elementary School
来源:互联网 发布:淘宝视频短片拍摄方案 编辑:程序博客网 时间:2024/05/17 10:42
Description
Johann Carl Friedrich Gau? (1777 - 1855) was one of the most important German mathematicians. For those of you who remember the Deutsche Mark, a picture of him was printed on the 10 ? DM bill. In elementary school, his teacher J. G. B?ttner tried to occupy the pupils by making them add up the integers from 1 to 100. The young Gau? surprised everybody by producing the correct answers (5050) within seconds.
Can you write a computer program that can compute such sums really quickly?
Given two integers n and m, you should compute the sum of all the integers from n to m. In other words, you should compute
Input
The first line contains the number of scenarios. Each scenario consists of a line containing the numbers n and m (−109 ≤ n ≤ m ≤ 109).
Output
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print the sum of all integers from n to m. Terminate the output for the scenario with a blank line.
Sample Input
31 100-11 10-89173 938749341
Sample Output
Scenario #1:5050Scenario #2:-11Scenario #3:440625159107385260
KEY:这题还好数据量不是很大,所以用_int64,给过了……(提交的时候要改成long long )
Source:
#include<iostream>
using namespace std;
int main()
...{
// freopen("fjnu_1943.in","r",stdin);
long long a,b;
int N;
int i;
long long j,sum=0;
cin>>N;
for(i=1;i<=N;i++)
...{
scanf("%lld%lld",&a,&b);
sum=(a+b)*(b-a+1)/2;
cout<<"Scenario #"<<i<<":"<<endl;
printf("%lld ",sum);
}
return 0;
}
- fjnu 1943 Gau? in Elementary School
- poj 2924 Gauß in Elementary School
- TOJ 2346.Gauß in Elementary School
- POJ 2924 Gauß in Elementary School 解题报告
- POJ 2924 Gauß in Elementary School(简单题)
- POJ 2924 Gauß in Elementary School(水~)
- POJ 2924 Gauß in Elementary School G++
- POJ 2924 Gauß in Elementary School(我的水题之路——n到m的连和)
- fjnu 1007 Ride to School
- The Changes in Our School
- FJNU
- school
- Hundreds Held Hostage at School in Russia
- How to Succeed in Graduate School
- English Vocabulary in Use Elementary, with Answers by Michael McCarthy
- Elementary Matrix Operations In Python https://github.com/vibrationtoolbox/vibration_toolbox
- fjnu 1291 The Party's in Dolores's Driveway
- 100+ Google Tricks That Will Save You Time in School
- .Net 中的反射(序章) - Part.1
- DataTable操作
- 如何建立高效率的测试团队----人员选择和培养1
- DataTable操作中的性能问题
- SOA 新业务语言 新系统架构——SOA原则
- fjnu 1943 Gau? in Elementary School
- xml文件提示下载,IE打不开
- fjnu 1412 An Interesting Set
- shell基础总结
- Isolate Your UI Code Before It Invades Your Business Layer
- 存储过程与函数的区别
- VBA教程
- #import no_namespace rename("EOF", "adoEOF")
- 听说是世界编程第一名(很简单,你也能实现)