Skip to content

Instantly share code, notes, and snippets.

@sicknarlo
Created December 17, 2014 15:30
Show Gist options
  • Save sicknarlo/103c2ab7a7699e969049 to your computer and use it in GitHub Desktop.
Save sicknarlo/103c2ab7a7699e969049 to your computer and use it in GitHub Desktop.
[HackerRank] *INCOMPLETE - TIMEOUT* Sherlock and Squares
/* Watson gives two integers A & B to Sherlock and asks if he can count the number
of square integers between A and B (both inclusive).
A square integer is an integer which is the square of any integer. For example, 1,
4, 9, 16 are some of the square integers as they are squares of 1, 2, 3, 4 respectively.
Input Format
First line contains T, the number of testcases. T test cases follow, each in a newline.
Each testcase contains two space separated integers denoting A and B.
Output Format
For each testcase, print the required answer in a new line.
Constraints
1 ≤ T ≤ 100
1 ≤ A ≤ B ≤ 109
*/
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int t, output[101];
cin >> t;
for (int i = 0; i < t; i++){
int firstNum, secondNum, count(0);
cin >> firstNum >> secondNum;
for (int j = firstNum; j <= secondNum; j++){
if (ceil(sqrt(j)) == sqrt(j))
count++;
output[i] = count;
}
}
for (int i = 0; i < t; i++)
cout << output[i] << endl;
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment