平方数
Problem Description
飞飞特别喜欢平方数,可是他数学并不好,你能帮他计算n与m之间所有平方数之和吗?
提示:若一个整数的开方还是整数,它就是平方数。例如:4、9、16、25是平方数。
Input
第一行 T 代表数据的组数。
接下来有 T 行,每行两个整数n,m (0 <= n, m <= 100000000)
Output
输出一个整数,代表所求区间内平方数之和。
Sample Input
3
1 4
3 10
17 20
Sample Output
5
13
0
#include <stdio.h>
#include <stdlib.h>
int main()
{
int t;
int n,m;
int i;
int temp;
int sum;
scanf("%d",&t);
while(t--)
{
sum=0;
scanf("%d %d",&n,&m);
if(n>m)
{
temp=n;
n=m;
m=temp;
}
for(i=n;i<=m;i++)
{
temp=sqrt(i);//sqrt是平方根
if(temp*temp==i)
sum+=i;
}
printf("%d\n",sum);
}
return 0;
}