-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathP169.java
54 lines (43 loc) · 1.16 KB
/
P169.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
169. Numbers
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard
output: standard
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
*
*/
import java.util.*;
public class P169 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int k = in.nextInt();
int res = 0;
if(k == 1)
res = 8;
if(k > 1) {
res = 1;
if((k - 1) % 3 == 0)
res++;
if((k + 5) % 3 == 0)
res++;
if((k - 1) % 6 == 0)
res++;
}
System.out.println(res);
}
}