4280 - Max Div K

From Bitnami MediaWiki
Revision as of 18:50, 29 March 2023 by Andor Giulia (talk | contribs) (Pagină nouă: == Rezolvare == <syntaxhighlight lang="python" line="1"> n, k = map(int, input().split()) numbers = list(map(int, input().split())) max_divisible = -1 for num in numbers: if num % k == 0 and num > max_divisible: max_divisible = num if max_divisible == -1: print("NU EXISTA") else: print(max_divisible) </syntaxhighlight>)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Rezolvare

<syntaxhighlight lang="python" line="1">

n, k = map(int, input().split()) numbers = list(map(int, input().split()))

max_divisible = -1 for num in numbers:

   if num % k == 0 and num > max_divisible:
       max_divisible = num

if max_divisible == -1:

   print("NU EXISTA")

else:

   print(max_divisible)

</syntaxhighlight>