Sunday 22 March 2009

The 9th Zhejiang University Programming Contest A

题目如下:
The 9th Zhejiang University Programming Contest - A
Square Root Day
Time Limit: 1 Second Memory Limit: 32768 KB
Square Root Day is an unofficial holiday celebrated on days when both the day of
the month and the month are the square root of either the last two or three
digits of the year. For example, the last Square Root Day was March 3, 2009
(3/3/09), and the next Square Root Day will be April 4, 2016 (4/4/16).

Input

The first line of the input contains an integer T (T <= 10), indicating the
number of cases.

Then T lines follows, each has two integers x and y (1 <= x <= y <= 2009).

Output

Output the number of Square Root Days from year x to year y, both inclusive.

Sample Input

2
2009 2009
81 100

Sample Output

1
2




#include <iostream>
#include <cmath>
using namespace std;
int calc(int from,int to){
int n=0;
for(;from<=to;++from) {
int x3=from%1000,x2=from%100;
if(x3==144) ++n;
if(x3==121) ++n;
if(x3==100) ++n;
if(x2==81) ++n;
if(x2==64) ++n;
if(x2==49) ++n;
if(x2==36) ++n;
if(x2==25) ++n;
if(x2==16) ++n;
if(x2==9) ++n;
if(x2==4) ++n;
if(x2==1) ++n;
}
return n;
}
int main() {
int n,f,t;
for(cin>>n;n&&cin>>f>>t;--n)
cout<<calc(f,t)<<endl;
return 0;
}



No comments:

Post a Comment