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)