• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codechef November Challenge 2013 Square Digit Squares

Square Digit Squares

Problem code: SDSQUARE                                                                        

  • Submit
  • My Submissions
  • All Submissions
 

Read problems statements in Mandarin Chinese and Russian.

Recently Chef become very much interested in perfect squares. We all know Chef and his weird interests. Anyways Chef will be soon writing his masters thesis on perfect squares revealing what-not-known properties of perfect squares.

While doing his research, he happened to be confronted with some interesting perfect squares. These prefect squares consists only of digits which are themselves perfect squares. 0, 1, 4 and 9 are such digits. These are called perfect digits.

As we all know Chef also has habit of asking too many questions, he is asking- given two numbers a and b, how many perfect squares exists between these two numbers inclusive, that contains only perfect digits. 

Input:

First line of input will contains T, number of test cases. Then T lines follows, each containing two positive integers a and b.

Constraints:

T <= 500

1<= a <= b <= 10000000000 

Output:

For each input, output number of perfect digit squares between given numbers. 

Sample

Input:

2

1 10

100 10000

Output:

3

9

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cstdlib>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define maxn 135
14 #define ll long long
15 #define mod 1000000007
16 #define INF 0x7fffffff
17 #define eps 1e-8
18 ll n,m;
19 ll a[maxn];
20 int main(){
21     int t,k=0;
22     for (ll i = 1; i <= 100000; i++){
23         ll s = i*i;
24         while (s){
25             ll x = s % 10;
26             if (x != 0 && x != 4 && x != 1 && x != 9)break;
27             s /= 10;
28         }
29         if (s==0)a[k++] = i*i;
30     }
31     scanf("%d", &t);
32     while (t--){
33         scanf("%lld%lld", &n,&m);
34         int l = lower_bound(a, a + k, n) - a;
35         int r = lower_bound(a, a + k, m) - a;
36         if (a[r] != m)r--;
37         printf("%d\n", r - l+1);
38     }
39     return 0;
40 }
View Code

 

posted @ 2013-11-02 11:50  HaibaraAi  阅读(160)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3