-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFairAndSquare.cpp
More file actions
52 lines (47 loc) · 792 Bytes
/
FairAndSquare.cpp
File metadata and controls
52 lines (47 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<sstream>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
using namespace std;
#define max 1000
int ispalin[max]={0};
int palin[max]={0};
void preprocess()
{
int i,count;
string lStr;
for (int lIter = 1; lIter <=max; ++lIter )
{
stringstream lStrS;
lStrS << lIter;
lStr = lStrS.str();
string lRevStr = lStr;
reverse( lRevStr.begin(), lRevStr.end() );
if ( lRevStr == lStr )
ispalin[lIter]=1;
}
for(i=1;i<=sqrt(max);i++)
{
if(ispalin[i] && ispalin[i*i])
palin[i*i]=1;
}
}
int main()
{
preprocess();
int i,a,b,c,t,uu=1;
cin>>t;
while(t--)
{
c=0;
cin>>a>>b;
for(i=a;i<=b;i++)
if(palin[i])
c++;
cout<<"case #"<<uu<<":"<<" "<<c<<endl;
uu++;
}
return 0;
}