Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:39
Show Gist options
  • Save pinglunliao/03af028ad549855eb9c0 to your computer and use it in GitHub Desktop.
Save pinglunliao/03af028ad549855eb9c0 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
int t, a, b;
cin >> t;
int sum[t];
int i = 0;
do {
cin >> a;
cin >> b;
int k = 1;
int sqrt = 1;
sum [i] = 0;
while(sqrt < a) {
k++;
sqrt = k * k;
}
//cout << "S:" << sqrt << endl;
if( sqrt <= b)
sum[i] = sqrt;
else
sum[i] = 0;
k++;
sqrt = k * k;
while(sqrt <= b) {
// cout << "S:" << sqrt << endl;
sum[i] += sqrt;
k++;
sqrt = k * k;
}
//cout << sum[i] << endl << endl;
i++;
} while(i < t);
for(i = 0; i < t; i++)
{
cout << "Case " << i + 1 << ": " << sum[i] << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment