建表
迴圈
輸入
找尋下界
持續相加直至上界
輸出
#include<iostream>
using namespace std;
int squareNum[32];
void setTable()
{
for(int i = 0; i < 32; i++)
squareNum[i] = i*i;
}
int main()
{
int T;
int a, b;
int total;
int i;
setTable();
while(cin >> T)
{
for(int times = 1; times<=T; times++)
{
cin >> a >> b;
total = 0;
for(i = 0 ; squareNum[i] < a; i++);
for(; squareNum[i] <= b; i++)
total += squareNum[i];
cout << "Case " << times << ": " << total << endl;
}
}
return 0;
}
全站熱搜
留言列表