XTU Happy Number (preprocessing)

Source: Internet
Author: User

Happy number
accepted:156 submit:371
Time limit:1000 MS Memory limit:65536 KB

Problem Description

Recently, Mr Xie learn the concept of happy number. A happy number is a number contain all digit 7 or as 1 digit other than 7. For example, 777 are a happy number because 777 contail all digit 7, 7177 and 87777 both happy number because only 1 digit Other than 7. Whereas 887,799 9807,12345, all of them is not happy number. Now Mr. Xie want to know for a given integer n, how many number among [1,n] is happy numbers, but counting them one by E is slow can I help him?

Input

First line an integer t indicate there is T testcases (1≤t≤100). Then T-lines follow, each line an integer n (1≤n≤106, n don ' t has leading zero).

Output

Output Case number First and then the answer.

Sample Input
517172030
Sample Output
Case 1:1case 2:7case 3:10case 4:10case 5:11

Sourcedaizhenyang




Analysis: Directly hit the table can be. Find with two points when searching.



AC Code:

#include <bits/stdc++.h>using namespace std;vector<int> p;void init () {for    (int i=1; i<1000000; i++) {        int ans = 0, j = i;        while (j) {            if (j%! = 7) ans + +;            J/=;        }        if (ans <= 1) p.push_back (i);}    } int main () {    #ifdef sxk        freopen ("In.txt", "R", stdin);    #endif//SXK    init ();    int t, N;    scanf ("%d", &t);    for (int i=1; i<=t; i++) {        scanf ("%d", &n);        printf ("Case%d:%d\n", I, Upper_bound (P.begin (), P.end (), N)-p.begin ());     Two-point lookup    }    return 0;}


XTU Happy Number (preprocessing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.