<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Vektorproblem]]></title><description><![CDATA[<p>ich mach grad was mit Vektoren und anscheinend habe ich etwas falsch gemacht mit ihnen (es kommt immer die fehlermeldung: vector subscript out of range (Vektorindex außerhalb des gültigen Bereichs)). hier mein code:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;fstream&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctime&gt;
using namespace std;

long potenz(long basis, int exponent) 
{ 
...  
} 

bool solovay_strassen_test(long n)
{
	long counter = 0, hilfe, h, loop = 1, b, x = 0, y, z; 
	int prim_true = 0;
	bool prim = false;
	vector&lt;long&gt;a; // Zufallszahl

	do 
	{
		srand( ( unsigned ) time ( NULL ) );
		a.push_back(rand () % n);

		while (a[loop] != 0)
		{
			h = a[loop] % n;
			a[loop] = n;
			b = h;
			a[loop] = x;
		}
		if (x == 1)
		{
			y = (a[loop] / n) % n;
			z = potenz(a[loop], (n-1) / 2) % n;

			if (y == z)
			{
				++prim_true;
			}
		}

		++loop;

	} while (prim_true &lt; 3 || loop &lt;= 5);

	if (loop - prim_true &lt; loop / 2)
	{
		return true;
	}

	else
	{
		return false;
	}
}
</code></pre>
<p>vielleicht könnte mir jemand sagen / ein tip geben , was ich falsch gemacht habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275499/vektorproblem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 22:21:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275499.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 Oct 2010 16:44:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 16:44:51 GMT]]></title><description><![CDATA[<p>ich mach grad was mit Vektoren und anscheinend habe ich etwas falsch gemacht mit ihnen (es kommt immer die fehlermeldung: vector subscript out of range (Vektorindex außerhalb des gültigen Bereichs)). hier mein code:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;fstream&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctime&gt;
using namespace std;

long potenz(long basis, int exponent) 
{ 
...  
} 

bool solovay_strassen_test(long n)
{
	long counter = 0, hilfe, h, loop = 1, b, x = 0, y, z; 
	int prim_true = 0;
	bool prim = false;
	vector&lt;long&gt;a; // Zufallszahl

	do 
	{
		srand( ( unsigned ) time ( NULL ) );
		a.push_back(rand () % n);

		while (a[loop] != 0)
		{
			h = a[loop] % n;
			a[loop] = n;
			b = h;
			a[loop] = x;
		}
		if (x == 1)
		{
			y = (a[loop] / n) % n;
			z = potenz(a[loop], (n-1) / 2) % n;

			if (y == z)
			{
				++prim_true;
			}
		}

		++loop;

	} while (prim_true &lt; 3 || loop &lt;= 5);

	if (loop - prim_true &lt; loop / 2)
	{
		return true;
	}

	else
	{
		return false;
	}
}
</code></pre>
<p>vielleicht könnte mir jemand sagen / ein tip geben , was ich falsch gemacht habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966163</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966163</guid><dc:creator><![CDATA[Gucky]]></dc:creator><pubDate>Fri, 15 Oct 2010 16:44:51 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 16:50:25 GMT]]></title><description><![CDATA[<p>In vielen Programmiersprachen beginnt man mit dem Zählen bei 0. Auch in C++. Das erste Element deines Vektors a ist a[0]. Daher greifst du im ersten Durchgang bei a[loop] auf ein nicht exisiterendes Element zu (loop ist am Anfang 1).</p>
<p>P.S.: Dein Code sieht aber auch sonst falsch aus.<br />
P.P.S.: Das srand willst du wahrscheinlich vor der Schleife haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966166</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 15 Oct 2010 16:50:25 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 16:58:05 GMT]]></title><description><![CDATA[<p>mir ist grad aufgefallen, ich hab eh die hälfte vergessen</p>
<p>hier der rest:</p>
<pre><code class="language-cpp">int main()
{
	long mittelzahl, loop;
	bool s;
	vector&lt;long&gt;primzahl;
	cout &lt;&lt; &quot;Welche Zahl soll die Mittelzahl bzw. trenner sein?&quot; &lt;&lt; endl;
	cin &gt;&gt; mittelzahl;

	// Mittelzahltest

	// erste Primzahl

	for (loop = 2; loop &lt; mittelzahl; ++loop)
	{
		s = solovay_strassen_test(loop);
		if (s = true)
		{
			primzahl.push_back(loop);
		}
	}
	return 0;
}
</code></pre>
<p>was meinst du mit der code sieht falsch aus??<br />
das andere hat geklappt aber jetzt passiert nichts wenn ich es ausführe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966171</guid><dc:creator><![CDATA[Gucky]]></dc:creator><pubDate>Fri, 15 Oct 2010 16:58:05 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 17:00:59 GMT]]></title><description><![CDATA[<blockquote>
<p>das andere hat geklappt aber jetzt passiert nichts wenn ich es ausführe</p>
</blockquote>
<p>Kann nicht sein... die Frage ist was passiert und was passieren soll...<br />
Also?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966177</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966177</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Fri, 15 Oct 2010 17:00:59 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 17:38:00 GMT]]></title><description><![CDATA[<p>Gucky schrieb:</p>
<blockquote>
<p>was meinst du mit der code sieht falsch aus??</p>
</blockquote>
<p>Ich sag's mal so: Wenn ich so etwas sehe:</p>
<pre><code class="language-cpp">long counter = 0, hilfe, h, loop = 1, b, x = 0, y, z;
    int prim_true = 0;
    bool prim = false;
</code></pre>
<p>Oder sowas:</p>
<pre><code class="language-cpp">do
    {
        srand( ( unsigned ) time ( NULL ) );
</code></pre>
<p>Oder dies:</p>
<pre><code class="language-cpp">if (loop - prim_true &lt; loop / 2)
    {
        return true;
    }

    else
    {
        return false;
    }
</code></pre>
<p>Oder doppelt schlimm dies( <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /> guck dir dies mal genauer an):</p>
<pre><code class="language-cpp">if (s = true)
        {
            primzahl.push_back(loop);
        }
</code></pre>
<p>Also wenn ich so etwas sehe, dann gibt mir das kein Vertrauen in den Code. Ich weiß dann aus Erfahrung, dass so schlechter Code auch meistens falsch ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966191</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 15 Oct 2010 17:38:00 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 18:55:51 GMT]]></title><description><![CDATA[<p>wenn ich in die if-bedingung direkt die funktion reinschreibe, kommt die fehlermeldung, es muss ein änderbarer lvalue sein, wenn du das meinst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966221</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966221</guid><dc:creator><![CDATA[Gucky]]></dc:creator><pubDate>Fri, 15 Oct 2010 18:55:51 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 18:57:32 GMT]]></title><description><![CDATA[<p>= ist eine Zuweisung, == ein Vergleich!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966225</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966225</guid><dc:creator><![CDATA[Oberon_0]]></dc:creator><pubDate>Fri, 15 Oct 2010 18:57:32 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 19:19:30 GMT]]></title><description><![CDATA[<p>sry ist mir auch grad aufgefallen</p>
<p>großer denkfehler</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966239</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966239</guid><dc:creator><![CDATA[Gucky]]></dc:creator><pubDate>Fri, 15 Oct 2010 19:19:30 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Fri, 15 Oct 2010 21:15:46 GMT]]></title><description><![CDATA[<p>Aus diesem Grund schreibe ich immer nur</p>
<pre><code class="language-cpp">if ( s ) 
        { 
            primzahl.push_back(loop); 
        }
</code></pre>
<p>Ist meiner Meinung nach genauso gut lesbar und es passiert einem nicht ein = anstatt einem == zu tippen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966271</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Fri, 15 Oct 2010 21:15:46 GMT</pubDate></item><item><title><![CDATA[Reply to Vektorproblem on Sat, 16 Oct 2010 08:35:55 GMT]]></title><description><![CDATA[<p>Oberon_0 schrieb:</p>
<blockquote>
<p>= ist eine Zuweisung, == ein Vergleich!</p>
</blockquote>
<p><em>Zuweisungen sind so lahm... Bei Vergleichen giebt's alles <strong>doppelt</strong>!</em> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1966342</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1966342</guid><dc:creator><![CDATA[lk]]></dc:creator><pubDate>Sat, 16 Oct 2010 08:35:55 GMT</pubDate></item></channel></rss>