题目信息:
你有两个整数L和R,你的任务是计算L与R之间数字的平方总和(包括L和R)
#include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
long long sum = 0, a, b;
scanf("%lld%lld", &a, &b);
if (a > b)
{
int t = a;
a = b;
b = t;
}
for(long long i = a; i <= b; i++)
sum += i * i;
printf("%lld\n", sum);
}
return 0;
}
分析:做这个题的时候应该注意两个问题(1)输入a与b的前后次序,因为a与b的大小是任意的。(2)定义数据时的类型。