SGU 169 numbers Mathematics

169.Numbers
Let us call P(n) - the product of all digits of number n (in decimal notation). 
For example, P(1243)=1*2*4*3=24; P(198501243)=0. 
Let us call n to be a good number, if (p(n)<>0) and (n mod P(n)=0). 
Let us call n to be a perfect number, if both n and n+1 are good numbers. 

You are to write a program, which, given the number K, counts all such 
numbers n that n is perfect and n contains exactly K digits in decimal notation.

Input
Only one number K (1<=K<=1000000) is written in input.

Output
Output the total number of perfect k-digit numbers.

Sample test(s)

Input
 
 
1
 
 

Output
 
 
8

 

Question meaning: a very interesting question, when I see this question, it is easy to think that this question is regular, but in the end, it is only found by looking for the solution.

The rule is to get the k-digit number except the single digit, all non-single digits are 1 through calculation, so just look at the situation of the last digit and how many perfect numbers can be formed by the previous numbers.

 

Assuming that the digits of n are a1, a2...ak, then the digits of n+1 are a1, a2...ak+1

Since n mod P(n)=0 is required, there are n=s1*a1*a2...*ak, n+1=s2*a1*a2...*(ak+1)

Here s1 and s2 must be integers because n mod P(n)=0 (because n must be m times P(n)), so there is 1=[s2*(ak+1)-s1*ak] *a1*a2...

From this, it can be concluded that a1, a2... must be 1

 

Let the one digit be x

x=1,   perfect numbers

x=2, perfect numbers when 6|(k-1)

x=3, no

x=4, no

x=5, perfect numbers when 3|(k-1)

x=6, it is perfect numbers when 6|(k-1)

x=7, no

x=8, no

Code:

 1 //#include"bits/stdc++.h"
 2 #include<sstream>
 3 #include<iomanip>
 4 #include"cstdio"
 5 #include"map"
 6 #include"set"
 7 #include"cmath"
 8 #include"queue"
 9 #include"vector"
10 #include"string"
11 #include"cstring"
12 #include"time.h"
13 #include"iostream"
14 #include"stdlib.h"
15 #include"algorithm"
16 #define db double
17 #define ll long long
18 #define vec vectr<ll>
19 #define mt  vectr<vec>
20 #define ci(x) scanf("%d",&x)
21 #define cd(x) scanf("%lf",&x)
22 #define cl(x) scanf("%lld",&x)
23 #define pi(x) printf("%d\n",x)
24 #define pd(x) printf("%f\n",x)
25 #define pl(x) printf("%lld\n",x)
26 //#define rep(i, x, y) for(int i=x;i<=y;i++)
27 #define rep(i, n) for(int i=0;i<n;i++)
28 const int N   = 1e4+ 5;
29 const int mod = 1e9 + 7;
30 const int MOD = mod - 1;
31 const int inf = 0x3f3f3f3f;
32 const db  PI  = acos(-1.0);
33 const db  eps = 1e-10;
34 using namespace std;
35 int k;
36 int main()
37 {
38     while(scanf("%d",&k)!=EOF)
39     {
40         k--;
41         int ans=1;
42         if(!k) puts("8");
43         else
44         {
45             if(k%3== 0 ) years+= 2 ;
46              if (k% 6 == 0 ) ans++ ;
47              ft(years);
48          }
 49      }
 50      return  0 ;
51 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325023133&siteId=291194637