//POJ 2924 等差公式求和
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long long a;
long long b;
int n;
cin>>n;
while(n && !cin.eof())
{
for(int i = 0; i < n; i++)
{
long long sum = 0;
cin>>a>>b;
cout<<"Scenario #"<<i+1<<":"<<endl;
if( a > 0)
{
sum += (a+b) * (b-a+1) / 2;
cout<<(long long)sum<<endl<<endl;
}
else
{
if(-a > b || -a > -b)
{
if(b > 0)
{
long long diff = -(a +
b);
sum += (a - (b+1)) *
diff / 2;
cout<<(long long)
sum<<endl<<endl;
}
else
{
sum += (a+b) * (b-a+1)
/ 2;
cout<<(long long)
sum<<endl<<endl;
}
}
else if (-a < b)
{
if(b > 0)
{
long long diff = a + b;
sum += (-a + 1 + b) *
diff / 2;
cout<<(long long)
sum<<endl<<endl;
}
}
else{
cout<<0<<endl<<endl;
}
}
}
cin>>n;
}
return 0;
}
POJ 2924
最新推荐文章于 2017-03-02 16:11:00 发布