<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2960_-_Abx</id>
	<title>2960 - Abx - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2960_-_Abx"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2960_-_Abx&amp;action=history"/>
	<updated>2026-05-01T06:39:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=2960_-_Abx&amp;diff=8952&amp;oldid=prev</id>
		<title>Corjuc Eunice: Pagină nouă: Un număr natural &lt;code&gt;n&lt;/code&gt; se numește putere dacă există două numere naturale &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;a ≥ 1&lt;/code&gt;, &lt;code&gt;b ≥ 2&lt;/code&gt; astfel încât . De exemplu, numerele &lt;code&gt;32&lt;/code&gt; , &lt;code&gt;169&lt;/code&gt; , &lt;code&gt;1&lt;/code&gt; sunt puteri ( ,  ,  ), iar &lt;code&gt;72&lt;/code&gt; , &lt;code&gt;2000&lt;/code&gt; și &lt;code&gt;31&lt;/code&gt; nu sunt puteri.  Se citesc numerele naturale &lt;code&gt;N&lt;/code&gt; , &lt;code&gt;M&lt;/code&gt; și un șir de &lt;code&gt;N&lt;/code&gt; numere naturale  din intervalul &lt;c...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2960_-_Abx&amp;diff=8952&amp;oldid=prev"/>
		<updated>2024-01-04T03:36:03Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Un număr natural &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; se numește putere dacă există două numere naturale &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;a ≥ 1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;b ≥ 2&amp;lt;/code&amp;gt; astfel încât . De exemplu, numerele &amp;lt;code&amp;gt;32&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;169&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; sunt puteri ( ,  ,  ), iar &amp;lt;code&amp;gt;72&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;2000&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;31&amp;lt;/code&amp;gt; nu sunt puteri.  Se citesc numerele naturale &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt; și un șir de &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale  din intervalul &amp;lt;c...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Un număr natural &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; se numește putere dacă există două numere naturale &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;a ≥ 1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;b ≥ 2&amp;lt;/code&amp;gt; astfel încât . De exemplu, numerele &amp;lt;code&amp;gt;32&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;169&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; sunt puteri ( ,  ,  ), iar &amp;lt;code&amp;gt;72&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;2000&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;31&amp;lt;/code&amp;gt; nu sunt puteri.&lt;br /&gt;
&lt;br /&gt;
Se citesc numerele naturale &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; , &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt; și un șir de &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale  din intervalul &amp;lt;code&amp;gt;[1,M]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Pentru fiecare din cele &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere  determinați câte un număr natural  din intervalul &amp;lt;code&amp;gt;[1,M]&amp;lt;/code&amp;gt;, cu proprietatea că  este o putere și pentru orice altă putere &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; din intervalul &amp;lt;code&amp;gt;[1,M]&amp;lt;/code&amp;gt; este îndeplinită condiția , unde &amp;lt;code&amp;gt;|x|&amp;lt;/code&amp;gt; reprezintă valoarea absolută a lui &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; (modulul).&lt;br /&gt;
&lt;br /&gt;
Dacă există două puteri egal depărtate de  se va alege puterea cea mai mică. De exemplu pentru numărul &amp;lt;code&amp;gt;26&amp;lt;/code&amp;gt;, dintre puterile &amp;lt;code&amp;gt;25&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;27&amp;lt;/code&amp;gt; va fi ales numărul &amp;lt;code&amp;gt;25&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;input.txt&amp;lt;/code&amp;gt; conține pe prima linie două numere &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt;, iar pe fiecare dintre următoarele &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; linii se găsește câte un număr natural  (&amp;lt;code&amp;gt;1 ≤ i ≤ N&amp;lt;/code&amp;gt;), cu semnificația de mai sus. Numerele aflate pe aceeași linie a fișierului sunt separate prin câte un spațiu.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;output.txt&amp;lt;/code&amp;gt; va conține &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; linii, pe fiecare linie &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;1 ≤ i ≤ N&amp;lt;/code&amp;gt;) aflându-se numărul natural  cu semnificația din enunț.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* 1&amp;lt;=n&amp;lt;=5000&lt;br /&gt;
* 10&amp;lt;=m&amp;lt;=10^18&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
8 1000&lt;br /&gt;
&lt;br /&gt;
345&lt;br /&gt;
&lt;br /&gt;
99&lt;br /&gt;
&lt;br /&gt;
999&lt;br /&gt;
&lt;br /&gt;
500&lt;br /&gt;
&lt;br /&gt;
123&lt;br /&gt;
&lt;br /&gt;
124&lt;br /&gt;
&lt;br /&gt;
99&lt;br /&gt;
&lt;br /&gt;
256&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
343&lt;br /&gt;
&lt;br /&gt;
100&lt;br /&gt;
&lt;br /&gt;
1000&lt;br /&gt;
&lt;br /&gt;
512&lt;br /&gt;
&lt;br /&gt;
121&lt;br /&gt;
&lt;br /&gt;
125&lt;br /&gt;
&lt;br /&gt;
100&lt;br /&gt;
&lt;br /&gt;
256&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
343 = 7^3&lt;br /&gt;
&lt;br /&gt;
100 = 10^2&lt;br /&gt;
&lt;br /&gt;
1000 = 10^3&lt;br /&gt;
&lt;br /&gt;
512 = 2^9&lt;br /&gt;
&lt;br /&gt;
121 = 11^2&lt;br /&gt;
&lt;br /&gt;
125 = 5^3&lt;br /&gt;
&lt;br /&gt;
100 = 10^2&lt;br /&gt;
&lt;br /&gt;
256 = 2^8&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
999999999999 1000&lt;br /&gt;
&lt;br /&gt;
345&lt;br /&gt;
&lt;br /&gt;
99&lt;br /&gt;
&lt;br /&gt;
999&lt;br /&gt;
&lt;br /&gt;
500&lt;br /&gt;
&lt;br /&gt;
123&lt;br /&gt;
&lt;br /&gt;
124&lt;br /&gt;
&lt;br /&gt;
99&lt;br /&gt;
&lt;br /&gt;
256&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Error: n is not within the valid range (1 &amp;lt;= n &amp;lt;= 5000)&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
import math&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
def verify_constraints(n, m):&lt;br /&gt;
    if not (1 &amp;lt;= n &amp;lt;= 5000):&lt;br /&gt;
        sys.exit(&amp;quot;Error: n is not within the valid range (1 &amp;lt;= n &amp;lt;= 5000)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    if not (10 &amp;lt;= m &amp;lt;= 10**18):&lt;br /&gt;
        sys.exit(&amp;quot;Error: m is not within the valid range (1 &amp;lt;= m &amp;lt;= 10^18)&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
def lgput(x, y):&lt;br /&gt;
    ans = 1&lt;br /&gt;
    aux = x&lt;br /&gt;
    p = 1&lt;br /&gt;
    while p &amp;lt;= y:&lt;br /&gt;
        if y &amp;amp; p:&lt;br /&gt;
            ans *= aux&lt;br /&gt;
        aux *= aux&lt;br /&gt;
        p &amp;lt;&amp;lt;= 1&lt;br /&gt;
    return ans&lt;br /&gt;
&lt;br /&gt;
def cautb(x, put):&lt;br /&gt;
    st = 1&lt;br /&gt;
    dr = int(x ** (1 / put))&lt;br /&gt;
    while st &amp;lt;= dr:&lt;br /&gt;
        mij = (st + dr) // 2&lt;br /&gt;
        if lgput(mij, put) &amp;gt; x:&lt;br /&gt;
            dr = mij - 1&lt;br /&gt;
        else:&lt;br /&gt;
            st = mij + 1&lt;br /&gt;
    return dr&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;input.txt&amp;quot;, &amp;quot;r&amp;quot;) as f, open(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;) as g:&lt;br /&gt;
    n, m = map(int, f.readline().split())&lt;br /&gt;
    verify_constraints(n, m)&lt;br /&gt;
    a_values = [int(f.readline()) for _ in range(n)]&lt;br /&gt;
&lt;br /&gt;
    for a in a_values:&lt;br /&gt;
        sol = 0&lt;br /&gt;
        dif = m + 100&lt;br /&gt;
        &lt;br /&gt;
        for j in range(2, 61):&lt;br /&gt;
            y = cautb(a, j)&lt;br /&gt;
            z = lgput(y, j)&lt;br /&gt;
            &lt;br /&gt;
            if abs(a - z) &amp;lt;= dif and z &amp;lt;= m:&lt;br /&gt;
                sol = z&lt;br /&gt;
                dif = abs(a - z)&lt;br /&gt;
            &lt;br /&gt;
            z = lgput(y + 1, j)&lt;br /&gt;
            &lt;br /&gt;
            if abs(a - z) &amp;lt; dif and z &amp;lt;= m:&lt;br /&gt;
                sol = z&lt;br /&gt;
                dif = abs(a - z)&lt;br /&gt;
        &lt;br /&gt;
        g.write(str(sol) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Corjuc Eunice</name></author>
	</entry>
</feed>