<?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=3401_-_Spp</id>
	<title>3401 - Spp - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=3401_-_Spp"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3401_-_Spp&amp;action=history"/>
	<updated>2026-05-01T04:37:47Z</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=3401_-_Spp&amp;diff=8953&amp;oldid=prev</id>
		<title>Corjuc Eunice: Pagină nouă: După o zi plină, trei băieți se joacă cu numere. În fiecare seară, unul dintre ei alege un număr &lt;code&gt;x&lt;/code&gt;, iar altul un număr &lt;code&gt;y&lt;/code&gt; mai mare sau egal cu &lt;code&gt;x&lt;/code&gt;. Al treilea propune ceva mai interesant. Astfel, el alege să le spună aproape instantaneu suma pătratelor perfecte de la &lt;code&gt;x&lt;/code&gt; și &lt;code&gt;y&lt;/code&gt;. Voi trebuie să rezolvați ceva asemănător, doar că știți numai ce zice primul și ultimul băiat. Pentru a-i verifica dacă...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3401_-_Spp&amp;diff=8953&amp;oldid=prev"/>
		<updated>2024-01-04T03:43:19Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: După o zi plină, trei băieți se joacă cu numere. În fiecare seară, unul dintre ei alege un număr &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;, iar altul un număr &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; mai mare sau egal cu &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;. Al treilea propune ceva mai interesant. Astfel, el alege să le spună aproape instantaneu suma pătratelor perfecte de la &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;. Voi trebuie să rezolvați ceva asemănător, doar că știți numai ce zice primul și ultimul băiat. Pentru a-i verifica dacă...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;După o zi plină, trei băieți se joacă cu numere. În fiecare seară, unul dintre ei alege un număr &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;, iar altul un număr &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; mai mare sau egal cu &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;. Al treilea propune ceva mai interesant. Astfel, el alege să le spună aproape instantaneu suma pătratelor perfecte de la &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;. Voi trebuie să rezolvați ceva asemănător, doar că știți numai ce zice primul și ultimul băiat. Pentru a-i verifica dacă greșesc la calcule, în schimb, trebuie să găsiți numărul pe care l-ar putea spune al doilea.&lt;br /&gt;
&lt;br /&gt;
Formal, pentru două numere &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; se definește &amp;lt;code&amp;gt;SPP(x,y) = x2&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;+ (x+1)2&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;+...+ y2&amp;lt;/code&amp;gt; (suma pătratelor perfecte de la &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Se dau &amp;lt;code&amp;gt;Q&amp;lt;/code&amp;gt; întrebări de tipul &amp;lt;code&amp;gt;x p&amp;lt;/code&amp;gt; și se cere cel mai mic &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; mai mare sau egal ca &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; pentru care &amp;lt;code&amp;gt;SPP(x,y) ≥ p2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Să se calculeze pentru fiecare întrebare &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; minimum, pentru care relația este satisfăcută.&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 un număr natural &amp;lt;code&amp;gt;Q&amp;lt;/code&amp;gt;. Pe liniile &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;, …, &amp;lt;code&amp;gt;Q+1&amp;lt;/code&amp;gt; se află câte o pereche &amp;lt;code&amp;gt;x p&amp;lt;/code&amp;gt; care satisface restricțiile.&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 răspunsul la fiecare întrebare.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Q ≤ 100.000&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
1 5&lt;br /&gt;
&lt;br /&gt;
10 19&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
12&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
1^2 + 2^2 + 3^2 + 4^2 = 30 &amp;gt;= 5^2&lt;br /&gt;
&lt;br /&gt;
10^2 + 11^2 + 12^2  = 365 &amp;gt;= 19^2&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
9999999999999&lt;br /&gt;
&lt;br /&gt;
1 5&lt;br /&gt;
&lt;br /&gt;
10 19&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Error: Q is not within the valid range (1 &amp;lt;= Q &amp;lt;= 100,000)&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 sys&lt;br /&gt;
&lt;br /&gt;
def verify_constraints(Q):&lt;br /&gt;
    if not (1 &amp;lt;= Q &amp;lt;= 100000):&lt;br /&gt;
        sys.exit(&amp;quot;Error: Q is not within the valid range (1 &amp;lt;= Q &amp;lt;= 100,000)&amp;quot;)&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;
    Q = int(f.readline())&lt;br /&gt;
    verify_constraints(Q)&lt;br /&gt;
    queries = [tuple(map(int, f.readline().split())) for _ in range(Q)]&lt;br /&gt;
&lt;br /&gt;
    for x, p in queries:&lt;br /&gt;
        def binarys(x, st, dr, pp):&lt;br /&gt;
            sol = 0&lt;br /&gt;
            px = (1 * x * (x + 1) * (2 * x + 1)) // 6&lt;br /&gt;
            while st &amp;lt;= dr:&lt;br /&gt;
                mid = (st + dr) // 2&lt;br /&gt;
                py = (1 * mid * (mid + 1) * (2 * mid + 1)) // 6&lt;br /&gt;
&lt;br /&gt;
                if py - px &amp;gt;= pp:&lt;br /&gt;
                    sol = mid&lt;br /&gt;
                    dr = mid - 1&lt;br /&gt;
                else:&lt;br /&gt;
                    st = mid + 1&lt;br /&gt;
            return sol&lt;br /&gt;
&lt;br /&gt;
        y = binarys(x - 1, x, x + 1500000, 1 * p * p)&lt;br /&gt;
        g.write(str(y) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Corjuc Eunice</name></author>
	</entry>
</feed>