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
4245 - Suma ONI
(section)
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!
== Rezolvare == <syntaxhighlight lang="python" line> #4245 def verifica_date_intrare(s): if s < 1 or s > 100000: print("Datele introduse nu corespund cerintelor.") exit() def cauta_suma_minimala(s): start_interval = 1 final_interval = 1000 suma_minima_gasita = 0 while start_interval <= final_interval: mijloc_interval = start_interval + (final_interval - start_interval) // 2 suma = mijloc_interval * (mijloc_interval + 1) // 2 if suma >= s: suma_minima_gasita = mijloc_interval final_interval = mijloc_interval - 1 else: start_interval = mijloc_interval + 1 diferenta = suma_minima_gasita * (suma_minima_gasita + 1) // 2 - s while diferenta & 1: suma_minima_gasita += 1 diferenta = suma_minima_gasita * (suma_minima_gasita + 1) // 2 - s return suma_minima_gasita, diferenta def afiseaza_rezultat(suma_minima_gasita, diferenta): fisier_iesire = open("sumaoni.out", "w") fisier_iesire.write(str(suma_minima_gasita) + '\n') if diferenta == 0: fisier_iesire.close() return if diferenta // 2 <= suma_minima_gasita: fisier_iesire.write(str(diferenta // 2)) fisier_iesire.close() return diferenta //= 2 for i in range(1, diferenta // 2 + 1): if diferenta - i <= suma_minima_gasita and diferenta - i != i: fisier_iesire.write(str(i) + '\n' + str(diferenta - i)) fisier_iesire.close() return fisier_iesire.close() if __name__ == '__main__': fisier_intrare = open("sumaoni.in", "r") s = int(fisier_intrare.readline()) fisier_intrare.close() verifica_date_intrare(s) suma_minima_gasita, diferenta = cauta_suma_minimala(s) if suma_minima_gasita is not None and diferenta is not None: print("Datele introduse corespund cerintelor.") afiseaza_rezultat(suma_minima_gasita, diferenta) </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