From fe0b8be5337834c9880d81e34bc134c0b879cfe8 Mon Sep 17 00:00:00 2001 From: Adam French Date: Thu, 24 Sep 2026 17:06:59 +0100 Subject: [PATCH] Solve nezzar-and-lucky-number --- .../nezzar-and-lucky-number/main.cpp | 37 +++++++++++++++++-- .../nezzar-and-lucky-number.in | 0 2 files changed, 34 insertions(+), 3 deletions(-) rename {solving => solved}/nezzar-and-lucky-number/main.cpp (71%) rename {solving => solved}/nezzar-and-lucky-number/nezzar-and-lucky-number.in (100%) diff --git a/solving/nezzar-and-lucky-number/main.cpp b/solved/nezzar-and-lucky-number/main.cpp similarity index 71% rename from solving/nezzar-and-lucky-number/main.cpp rename to solved/nezzar-and-lucky-number/main.cpp index b676916..7fce99f 100644 --- a/solving/nezzar-and-lucky-number/main.cpp +++ b/solved/nezzar-and-lucky-number/main.cpp @@ -14,6 +14,7 @@ typedef vector vi; #define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str()) #define NL '\n' #define CM ", " +#define SP " " // ----- FOR LOOPS ----- #define F(i,L,R) for (int i = L; i < R; i++) @@ -56,8 +57,38 @@ typedef vector vi; #define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) #define pb push_back + int main() { - STDIO("nezzar-and-lucky-number"); - takeI(n); - DBG(n); + FASTIO; + takeI(t); + while (t--) { + takeII(n, d); + takeV(a, n); + + bool dp[100]; + memset(dp, false, sizeof(dp)); + dp[d] = true; + dp[10*d] = true; + for (int i = 0; i < 10; i++) { + dp[10*i + d] = true; + } + + for (int i = 0; i < 100; i++) { + for (int j = i; j < 100; j++) { + if (dp[i] && dp[j-i]) dp[j] = true; + } + } + + for (auto x : a) { + int res = true; + int r = x % d; + // If x % d == 0 then x = d + d + d .. + d k times + if (r == 0) goto fin; + // Use 10*d + r, then x + (10* d + r) % d = r - r = 0 + if (x >= 10*d + r) goto fin; + res = dp[x]; + fin: + YESNO(res); + } + } } diff --git a/solving/nezzar-and-lucky-number/nezzar-and-lucky-number.in b/solved/nezzar-and-lucky-number/nezzar-and-lucky-number.in similarity index 100% rename from solving/nezzar-and-lucky-number/nezzar-and-lucky-number.in rename to solved/nezzar-and-lucky-number/nezzar-and-lucky-number.in