An Easy Problem
時間限制: 1000 ms | 記憶體限制: 65535 KB 難度: 1
- 描述
- In this problem, you are given two integers L and R, and your task is to calculate the sum of all the number's square between L and R(inclusive).
- 輸入
-
The first line contains an integer T, indicates the number of test case.
The next T lines, each line contains two integers L and R(1≤L,R≤10^5).
輸出 - Print an integer represents the sum. 樣例輸入
-
2 1 2 2 4
樣例輸出 -
5 29
來源 - 原創 上傳者
- TC_李遠航
-
- 考慮L大于R的情況!!!!!!!
-
#include<cstdio> #include<iostream> using namespace std; main() { int n; cin>>n; while(n--) { long long sum=0; int a,b; cin>>a>>b; if(a>b) { int temp= a; a=b; b=temp; } sum=b*(b+1)*(2*b+1)/6-a*(a+1)*(2*a+1)/6+a*a; cout<<sum<<endl; } return 0; }