Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1023 - Cmmdc 3
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Cerinţa == Se dă un sir cu <code>n</code> elemente, numere naturale nenule. Folosind metoda Divide et Impera, determinaţi cel mai mare divizor comun al elementelor acestui șir. == Date de intrare == Programul citește de la tastatură numărul <code>n</code>, iar cele <code>n</code> elemente ale șirului. == Date de ieşire == Programul afișează pe ecran numărul <code>X</code>, reprezentând cel mai mare divizor comun al elementelor. = Restricţii şi precizări = * <code>1 ≤ n ≤ 1000</code> * elementele șirului vor avea cel mult <code>9</code> cifre * se recomandă folosirea metodei Divide et Impera * = Exemplul 1 = Date de intrare 7 18 54 24 42 108 60 30 Date de ieșire 6 == Exemplul 2 == Date de intrare 1001 123 Numerele introduse nu respectă restricțiile.<syntaxhighlight lang="python3" line="1"> def verifica_restrictii(n, arr): if 1 <= n <= 1000 and all(1 <= num <= 10**9 for num in arr): return True return False def cmmd(x, y): while y: x, y = y, x % y return x def cmmd_divide_et_impera(arr, start, end): if start == end: return arr[start] else: mid = (start + end) // 2 left_cmmd = cmmd_divide_et_impera(arr, start, mid) right_cmmd = cmmd_divide_et_impera(arr, mid + 1, end) return cmmd(left_cmmd, right_cmmd) def main(): n = int(input("Introduceți numărul n: ")) arr = list(map(int, input("Introduceți cele n elemente separate prin spațiu: ").split())) if verifica_restrictii(n, arr): rezultat = cmmd_divide_et_impera(arr, 0, n - 1) print("Cel mai mare divizor comun:", rezultat) else: print("Numerele introduse nu respectă restricțiile.") if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width