Aveiro_quanyue's blog

By Aveiro_quanyue, history, 19 months ago, In English

You are given $$$n$$$ '2' and $$$m$$$ '3'. Try to concatenate these $$$n+m$$$ characters into a largest base-10 number $$$d$$$ such that $$$2023 \mid d$$$. If you cannot get such $$$d$$$, print $$$-1$$$.

Example $$$1$$$:

Input: $$$n = 2, m = 8$$$.

Output: $$$d = 2233333333$$$. Please note that $$$2233333333 = 2023 \times 1103971$$$, and it is the largest.

Example $$$2$$$:

Input: $$$n = 2, m = 2$$$.

Output: $$$-1$$$ (no solution).

Constraints: $$$1 \leq n,m \leq 1e6$$$. Time $$$1s$$$, memory $$$256MB$$$.

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
19 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Brute force code:

Spoiler

Result:

Spoiler