문제 링크

요약

  • 쉬운 문제

최종

  • Testcase 가 작기 때문에 무지성으로 풀어도 된다. 그게 시간을 절약하는 길이다.
class Solution {
	int product(int a) {
		int acc = 1;
 
		while (a) {
			acc *= a % 10;
			a /= 10;
		}
 
		return acc;
	}
public:
	int smallestNumber(int n, int t) {
		for (int i = n; 0 < i; i++) {
			if (product(i) % t == 0) {
				return i;
			}
		}
 
		// Should not happen
		return -1;
	}
};