<?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=2897_-_numere26</id>
	<title>2897 - numere26 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2897_-_numere26"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2897_-_numere26&amp;action=history"/>
	<updated>2026-05-01T05:39:16Z</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=2897_-_numere26&amp;diff=9049&amp;oldid=prev</id>
		<title>Miawinator: Pagină nouă: Se consideră un șir format din &lt;code&gt;n&lt;/code&gt; numere naturale. Asupra numerelor din șir se face următoarea prelucrare: fiecare valoare este înlocuită cu cel mai mare divizor prim al său. În noul șir se formează secvențe de numere care încep și se termină cu aceeași valoare, numite secvențe neuniforme.  = Cerința = Cunoscând numerele naturale &lt;code&gt;n&lt;/code&gt; și &lt;code&gt;c&lt;/code&gt;, și un șir de &lt;code&gt;n&lt;/code&gt; numere naturale, se cere să se rezolve următoarele...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2897_-_numere26&amp;diff=9049&amp;oldid=prev"/>
		<updated>2024-01-05T00:14:30Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Se consideră un șir format din &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale. Asupra numerelor din șir se face următoarea prelucrare: fiecare valoare este înlocuită cu cel mai mare divizor prim al său. În noul șir se formează secvențe de numere care încep și se termină cu aceeași valoare, numite secvențe neuniforme.  = Cerința = Cunoscând numerele naturale &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt;, și un șir de &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale, se cere să se rezolve următoarele...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Se consideră un șir format din &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale. Asupra numerelor din șir se face următoarea prelucrare: fiecare valoare este înlocuită cu cel mai mare divizor prim al său. În noul șir se formează secvențe de numere care încep și se termină cu aceeași valoare, numite secvențe neuniforme.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Cunoscând numerele naturale &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt;, și un șir de &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale, se cere să se rezolve următoarele cerințe:&lt;br /&gt;
&lt;br /&gt;
1. dacă &amp;lt;code&amp;gt;c = 1&amp;lt;/code&amp;gt;, atunci se cere să se afișeze lungimea maximă a unei secvențe neuniforme.&lt;br /&gt;
&lt;br /&gt;
2. dacă &amp;lt;code&amp;gt;c = 2&amp;lt;/code&amp;gt;, atunci se cere să se afișeze numărul total de secvențe neuniforme din șir.&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, despărțite prin câte un spațiu, numerele naturale &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt;, cu semnificația din enunț. A doua linie conține &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale, despărțite prin câte un spațiu.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Dacă &amp;lt;code&amp;gt;c = 1&amp;lt;/code&amp;gt;, atunci pe prima linie a fișierului &amp;lt;code&amp;gt;output.txt&amp;lt;/code&amp;gt; va fi scris un singur număr ce reprezintă lungimea maximă a unei secvențe neuniforme. Dacă &amp;lt;code&amp;gt;c = 2&amp;lt;/code&amp;gt;, atunci fișierul &amp;lt;code&amp;gt;output.txt&amp;lt;/code&amp;gt; va conține un singur număr ce reprezintă numărul total de secvențe neuniforme.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;0 &amp;lt; n &amp;lt; 10.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;
6  1&lt;br /&gt;
&lt;br /&gt;
14 2 49 3 35 1024  &lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
5&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Cele &amp;lt;code&amp;gt;10&amp;lt;/code&amp;gt; numere sunt înlocuite cu valorile: &amp;lt;code&amp;gt;7&amp;lt;/code&amp;gt;, &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;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;. Numărul total de secvențe neuniforme din șir este &amp;lt;code&amp;gt;3 + 3 + 3 = 9&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
10 2&lt;br /&gt;
&lt;br /&gt;
14 8 3 25 6 24 20 1024 100 2&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
9&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Cele &amp;lt;code&amp;gt;10&amp;lt;/code&amp;gt; numere sunt înlocuite cu valorile: &amp;lt;code&amp;gt;7&amp;lt;/code&amp;gt;, &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;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;. Numărul total de secvențe neuniforme din șir este &amp;lt;code&amp;gt;3 + 3 + 3 = 9&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 3 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
999999999999 2&lt;br /&gt;
&lt;br /&gt;
14 8 3 25 6 24 20 1024 100 2&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Input-ul nu convine conditiilor&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;
def verificare(n):&lt;br /&gt;
    if not(1&amp;lt;=n&amp;lt;=10000):&lt;br /&gt;
        print(&amp;quot;Input-ul nu convine conditiilor&amp;quot;)&lt;br /&gt;
        exit()&lt;br /&gt;
&lt;br /&gt;
def fact_max(a):&lt;br /&gt;
    f = 2&lt;br /&gt;
    r = 0&lt;br /&gt;
    if a % 2 == 0:&lt;br /&gt;
        r = 2&lt;br /&gt;
        while a % 2 == 0:&lt;br /&gt;
            a //= 2&lt;br /&gt;
    for f in range(3, a + 1, 2):&lt;br /&gt;
        if a % f == 0:&lt;br /&gt;
            r = f&lt;br /&gt;
            while a % f == 0:&lt;br /&gt;
                a //= f&lt;br /&gt;
    return r&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;input.txt&amp;quot;, &amp;quot;r&amp;quot;) as fin, open(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;) as fout:&lt;br /&gt;
        s = 0&lt;br /&gt;
        n, c = map(int, fin.readline().split())&lt;br /&gt;
        verificare(n)&lt;br /&gt;
        fr1 = [0] * 10000&lt;br /&gt;
        fr2 = [0] * 10000&lt;br /&gt;
        mx = 0&lt;br /&gt;
        lmax = 0&lt;br /&gt;
&lt;br /&gt;
        l=list(map(int, fin.readline().split()))&lt;br /&gt;
&lt;br /&gt;
        for i in range(1, n + 1):&lt;br /&gt;
            a = l[i-1]&lt;br /&gt;
            x = fact_max(a)&lt;br /&gt;
&lt;br /&gt;
            if x &amp;gt; mx:&lt;br /&gt;
                mx = x  # cel mai mare nr prim care apare in urma prelucrarii sirului initial&lt;br /&gt;
&lt;br /&gt;
            # cerinta 1&lt;br /&gt;
            if fr1[x] == 0:&lt;br /&gt;
                fr1[x] = i&lt;br /&gt;
            else:&lt;br /&gt;
                d = i - fr1[x] + 1&lt;br /&gt;
                if d &amp;gt; lmax:&lt;br /&gt;
                    lmax = d&lt;br /&gt;
&lt;br /&gt;
            # cerinta 2&lt;br /&gt;
            fr2[x] += 1&lt;br /&gt;
&lt;br /&gt;
        if c == 1:&lt;br /&gt;
            fout.write(str(lmax) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
        else:&lt;br /&gt;
            # rezolvarea de la cerinta 2&lt;br /&gt;
            # calculez suma de x*(x-1)/2, unde x=fr2[i]&lt;br /&gt;
&lt;br /&gt;
            if fr2[2] &amp;gt; 1:&lt;br /&gt;
                s += fr2[2] * (fr2[2] - 1) // 2&lt;br /&gt;
&lt;br /&gt;
            # i-au mai ramas numai valori prime impare&lt;br /&gt;
            for i in range(3, mx + 1, 2):&lt;br /&gt;
                if fr2[i] &amp;gt; 1:&lt;br /&gt;
                    s += fr2[i] * (fr2[i] - 1) // 2&lt;br /&gt;
&lt;br /&gt;
            fout.write(str(s) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Miawinator</name></author>
	</entry>
</feed>