<?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=3045_-_Pro_3</id>
	<title>3045 - Pro 3 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=3045_-_Pro_3"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3045_-_Pro_3&amp;action=history"/>
	<updated>2026-05-01T06:34:00Z</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=3045_-_Pro_3&amp;diff=9063&amp;oldid=prev</id>
		<title>Miawinator: Pagină nouă: Se consideră 3 progresii aritmetice de numere naturale nenule. Notăm cu &lt;code&gt;Pi&lt;/code&gt;, &lt;code&gt;1 ≤ i ≤ 3&lt;/code&gt;, mulțimile formate cu elementele progresiei &lt;code&gt;i&lt;/code&gt;. Fie &lt;code&gt;P = P1&lt;/code&gt;  &lt;code&gt;P2&lt;/code&gt;  &lt;code&gt;P3&lt;/code&gt; reuniunea mulțimilor &lt;code&gt;P1&lt;/code&gt;, &lt;code&gt;P2&lt;/code&gt;, &lt;code&gt;P3&lt;/code&gt;.  = Cerința = Să se determine cardinalul mulțimii &lt;code&gt;P&lt;/code&gt;.  = Date de intrare = Fișierul de intrare &lt;code&gt;input.txt&lt;/code&gt; conține &lt;code&gt;3&lt;/code&gt; linii. Pe l...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3045_-_Pro_3&amp;diff=9063&amp;oldid=prev"/>
		<updated>2024-01-05T02:52:28Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Se consideră 3 progresii aritmetice de numere naturale nenule. Notăm cu &amp;lt;code&amp;gt;Pi&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;1 ≤ i ≤ 3&amp;lt;/code&amp;gt;, mulțimile formate cu elementele progresiei &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;. Fie &amp;lt;code&amp;gt;P = P1&amp;lt;/code&amp;gt;  &amp;lt;code&amp;gt;P2&amp;lt;/code&amp;gt;  &amp;lt;code&amp;gt;P3&amp;lt;/code&amp;gt; reuniunea mulțimilor &amp;lt;code&amp;gt;P1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;P2&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;P3&amp;lt;/code&amp;gt;.  = Cerința = Să se determine cardinalul mulțimii &amp;lt;code&amp;gt;P&amp;lt;/code&amp;gt;.  = Date de intrare = Fișierul de intrare &amp;lt;code&amp;gt;input.txt&amp;lt;/code&amp;gt; conține &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt; linii. Pe l...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Se consideră 3 progresii aritmetice de numere naturale nenule. Notăm cu &amp;lt;code&amp;gt;Pi&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;1 ≤ i ≤ 3&amp;lt;/code&amp;gt;, mulțimile formate cu elementele progresiei &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;. Fie &amp;lt;code&amp;gt;P = P1&amp;lt;/code&amp;gt;  &amp;lt;code&amp;gt;P2&amp;lt;/code&amp;gt;  &amp;lt;code&amp;gt;P3&amp;lt;/code&amp;gt; reuniunea mulțimilor &amp;lt;code&amp;gt;P1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;P2&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;P3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Să se determine cardinalul mulțimii &amp;lt;code&amp;gt;P&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 &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt; linii. Pe linia &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;1 ≤ i ≤ 3&amp;lt;/code&amp;gt; se vor găsi câte trei numere naturale &amp;lt;code&amp;gt;ai&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ri&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ni&amp;lt;/code&amp;gt;, separate prin câte un spațiu, ce reprezintă în această ordine primul termen, rația și numărul de termeni ai progresiei &amp;lt;code&amp;gt;Pi&amp;lt;/code&amp;gt;.&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 pe prima linie cardinalul mulțimii &amp;lt;code&amp;gt;P&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplu ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
2 2 10&lt;br /&gt;
&lt;br /&gt;
3 4 8&lt;br /&gt;
&lt;br /&gt;
1 3 12&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
24&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Prima progresie are primul termen &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;, rația &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;10&amp;lt;/code&amp;gt; termeni.&lt;br /&gt;
&lt;br /&gt;
A doua progresie are primul termen &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;, rația &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt; termeni.&lt;br /&gt;
&lt;br /&gt;
A treia progresie are primul termen &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, rația &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;12&amp;lt;/code&amp;gt; termeni.&lt;br /&gt;
&lt;br /&gt;
Așadar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;P1&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;P2&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= {3, 7, 11, 15, 19, 23, 27, 31}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;P3&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;= {1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reuniunea termenilor celor trei progresii este mulțimea&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;P = {1, 2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 22, 23, 25, 27, 28, 31, 34}&amp;lt;/code&amp;gt; și cardinalul mulțimii &amp;lt;code&amp;gt;P&amp;lt;/code&amp;gt; este &amp;lt;code&amp;gt;24&amp;lt;/code&amp;gt;.&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;
class Progresie:&lt;br /&gt;
    def __init__(self, first, ratio, n):&lt;br /&gt;
        self.first = first&lt;br /&gt;
        self.ratio = ratio&lt;br /&gt;
        self.n = n&lt;br /&gt;
&lt;br /&gt;
def read():&lt;br /&gt;
    with open(&amp;quot;input.txt&amp;quot;, &amp;quot;r&amp;quot;) as f:&lt;br /&gt;
        x_values = list(map(int, f.readline().split()))&lt;br /&gt;
        y_values = list(map(int, f.readline().split()))&lt;br /&gt;
        z_values = list(map(int, f.readline().split()))&lt;br /&gt;
    &lt;br /&gt;
    return Progresie(*x_values), Progresie(*y_values), Progresie(*z_values)&lt;br /&gt;
&lt;br /&gt;
def cmmdc(a, b):&lt;br /&gt;
    while b != 0:&lt;br /&gt;
        a, b = b, a % b&lt;br /&gt;
    return a&lt;br /&gt;
&lt;br /&gt;
def cmmmc(a, b):&lt;br /&gt;
    return a * b // cmmdc(a, b)&lt;br /&gt;
&lt;br /&gt;
def calc(a, b):&lt;br /&gt;
    Maxa = a.first + a.ratio * (a.n - 1)&lt;br /&gt;
    Maxb = b.first + b.ratio * (b.n - 1)&lt;br /&gt;
    Min = min(Maxa, Maxb)&lt;br /&gt;
    for i in range(int(1e6)):&lt;br /&gt;
        nr = a.first + i * a.ratio&lt;br /&gt;
        if nr &amp;gt;= b.first and nr &amp;lt;= Min and (nr - b.first) % b.ratio == 0:&lt;br /&gt;
            return Progresie(nr, cmmmc(a.ratio, b.ratio), (Min - nr) // cmmmc(a.ratio, b.ratio) + 1)&lt;br /&gt;
    return Progresie(0, 0, 0)&lt;br /&gt;
&lt;br /&gt;
def solve(x, y, z):&lt;br /&gt;
    xy = calc(x, y)&lt;br /&gt;
    xz = calc(x, z)&lt;br /&gt;
    yz = calc(y, z)&lt;br /&gt;
    xyz = calc(xy, z)&lt;br /&gt;
    return x.n + y.n + z.n - xy.n - xz.n - yz.n + xyz.n&lt;br /&gt;
&lt;br /&gt;
def output(rez):&lt;br /&gt;
    with open(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;) as g:&lt;br /&gt;
        g.write(str(rez))&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    x, y, z = read()&lt;br /&gt;
    rez = solve(x, y, z)&lt;br /&gt;
    output(rez)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Miawinator</name></author>
	</entry>
</feed>