-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialMultiple.java
33 lines (31 loc) · 1.06 KB
/
SpecialMultiple.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
package com.harrymdev.hackerrank.solutions;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;
public class SpecialMultiple {
private static Pattern pattern = Pattern.compile("[90]+");
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
Map<Integer, Long> values = new HashMap<>();
while(t-- > 0) {
int n = scanner.nextInt();
Long value = values.get(n);
if (value != null) {
System.out.println(value);
} else {
long multiplier = 1;
do {
long tempAnswer = n * multiplier++;
if (pattern.matcher(String.valueOf(tempAnswer)).matches()) {
value = tempAnswer;
values.put(n, value);
System.out.println(value);
}
} while (value == null);
}
}
scanner.close();
}
}