<?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=3775_-_Prosum</id>
	<title>3775 - Prosum - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=3775_-_Prosum"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3775_-_Prosum&amp;action=history"/>
	<updated>2026-05-01T04:33:32Z</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=3775_-_Prosum&amp;diff=8988&amp;oldid=prev</id>
		<title>Corjuc Eunice: Pagină nouă: Se dau &lt;code&gt;N&lt;/code&gt; numere naturale &lt;code&gt;a[1], a[2], ..., a[N]&lt;/code&gt; şi un număr natural nenul &lt;code&gt;M&lt;/code&gt;.  = Cerința = Să se determine numărul perechilor de indici &lt;code&gt;(i, j)&lt;/code&gt;, cu &lt;code&gt;i &lt; j&lt;/code&gt;, cu proprietatea că numărul &lt;code&gt;a[i]*a[j]+a[i]+a[j]&lt;/code&gt; este divizibil cu &lt;code&gt;M&lt;/code&gt;.  = Date de intrare = Fișierul de intrare &lt;code&gt;input.txt&lt;/code&gt; conține pe prima linie numerele naturale &lt;code&gt;N&lt;/code&gt; şi &lt;code&gt;M&lt;/code&gt;, iar pe următoarea l...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=3775_-_Prosum&amp;diff=8988&amp;oldid=prev"/>
		<updated>2024-01-04T16:49:30Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Se dau &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale &amp;lt;code&amp;gt;a[1], a[2], ..., a[N]&amp;lt;/code&amp;gt; şi un număr natural nenul &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt;.  = Cerința = Să se determine numărul perechilor de indici &amp;lt;code&amp;gt;(i, j)&amp;lt;/code&amp;gt;, cu &amp;lt;code&amp;gt;i &amp;lt; j&amp;lt;/code&amp;gt;, cu proprietatea că numărul &amp;lt;code&amp;gt;a[i]*a[j]+a[i]+a[j]&amp;lt;/code&amp;gt; este divizibil cu &amp;lt;code&amp;gt;M&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 pe prima linie numerele naturale &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 următoarea l...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Se dau &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale &amp;lt;code&amp;gt;a[1], a[2], ..., a[N]&amp;lt;/code&amp;gt; şi un număr natural nenul &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Să se determine numărul perechilor de indici &amp;lt;code&amp;gt;(i, j)&amp;lt;/code&amp;gt;, cu &amp;lt;code&amp;gt;i &amp;lt; j&amp;lt;/code&amp;gt;, cu proprietatea că numărul &amp;lt;code&amp;gt;a[i]*a[j]+a[i]+a[j]&amp;lt;/code&amp;gt; este divizibil cu &amp;lt;code&amp;gt;M&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 numerele naturale &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 următoarea linie cele &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale &amp;lt;code&amp;gt;a[1], a[2], ..., a[N]&amp;lt;/code&amp;gt;, separate prin 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 pe prima linie numărul perechilor de indici &amp;lt;code&amp;gt;(i, j)&amp;lt;/code&amp;gt;, cu &amp;lt;code&amp;gt;i &amp;lt; j&amp;lt;/code&amp;gt;, cu proprietatea că numărul &amp;lt;code&amp;gt;a[i]*a[j]+a[i]+a[j]&amp;lt;/code&amp;gt; este divizibil cu &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;2 ≤ N ≤ 100.000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;0 ≤ a[i] ≤ 1018&amp;lt;/code&amp;gt;, pentru orice &amp;lt;code&amp;gt;i∈{1, 2, ..., N}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ M ≤ 1017&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
4 13&lt;br /&gt;
&lt;br /&gt;
6 15 6 1&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Există două perechi de indici având proprietatea cerută, &amp;lt;code&amp;gt;(1,4)&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt;, deoarece avem &amp;lt;code&amp;gt;6*1+6+1=13&amp;lt;/code&amp;gt;, care este divizibil cu &amp;lt;code&amp;gt;M=13&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
99999999999999 13&lt;br /&gt;
&lt;br /&gt;
6 15 6 1&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Invalid input. Please check the constraints.&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 is_valid_input(N, M, numbers):&lt;br /&gt;
    if not (2 &amp;lt;= N &amp;lt;= 100000):&lt;br /&gt;
        return False&lt;br /&gt;
    if not (1 &amp;lt;= M &amp;lt;= 10**17):&lt;br /&gt;
        return False&lt;br /&gt;
    if not all(0 &amp;lt;= a_i &amp;lt;= 10**18 for a_i in numbers):&lt;br /&gt;
        return False&lt;br /&gt;
    return True&lt;br /&gt;
&lt;br /&gt;
def count_pairs_with_property(N, M, numbers):&lt;br /&gt;
    count = 0&lt;br /&gt;
    for i in range(N):&lt;br /&gt;
        for j in range(i + 1, N):&lt;br /&gt;
            if (numbers[i] * numbers[j] + numbers[i] + numbers[j]) % M == 0:&lt;br /&gt;
                count += 1&lt;br /&gt;
    return count&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:&lt;br /&gt;
        N, M = map(int, fin.readline().split())&lt;br /&gt;
        numbers = list(map(int, fin.readline().split()))&lt;br /&gt;
&lt;br /&gt;
    if not is_valid_input(N, M, numbers):&lt;br /&gt;
        print(&amp;quot;Invalid input. Please check the constraints.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    result = count_pairs_with_property(N, M, numbers)&lt;br /&gt;
&lt;br /&gt;
    with open(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;) as fout:&lt;br /&gt;
        fout.write(str(result) + &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>Corjuc Eunice</name></author>
	</entry>
</feed>