Wer kann die schnellsten Primzahlen?



  • bringt euren code einfach zum treffen mit.
    wer nicht kommt, kann auch nach volkard@gmx.net schicken.



  • der gewinner ist 0xdeadbeef.

    der gewinnercode:

    /*	$NetBSD: pr_tbl.c,v 1.7 2003/08/07 09:37:33 agc Exp $	*/
    
    /*
     * Copyright (c) 1989, 1993
     *	The Regents of the University of California.  All rights reserved.
     *
     * This code is derived from software contributed to Berkeley by
     * Landon Curt Noll.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     * 1. Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     * 2. Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     * 3. Neither the name of the University nor the names of its contributors
     *    may be used to endorse or promote products derived from this software
     *    without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     * SUCH DAMAGE.
     */
    
    #include <stdio.h>
    
    unsigned long const primes[] = {
    2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,
    ...und so weiter...
    65407,65413,65419,65423,65437,65447,65449,65479,65497,65519,65521,65537,0
    };
    
    bool isPrime(unsigned long long x) {
      unsigned long long i;
      unsigned j;
    
      if(x == 2 || x == 3 || x == 5 || x == 7)
        return 1;
      if(x < 2 || x % 2 == 0 || x % 3 == 0 || x % 5 == 0 || x % 7 == 0)
        return 0;
    
      if(x <= 65537 * 65537) {
        for(i = 4; primes[i] * primes[i] <= x; ++i)
          if(x % primes[i] == 0)
    	return 0;
      } else {
        for(i = 4; primes[i]; ++i) 
          if(x % primes[i] == 0)
    	return 0;
        j = 2;
        for(i = primes[i - 1] + 2; i * i <= x; i += (j = 6 - j))
          if(x % i == 0)
    	return 0;
      }
    
      return 1;
    }
    //nebst der main, die schon gepostet wurde
    


  • Wer hat überhaupt alles mitgemacht?



  • interessanter wäre... schrieb:

    Wer hat überhaupt alles mitgemacht?

    nur er.



  • ROFLMAO! 🤡



  • Schlägt er denn deine Variante, volkard?



  • Nein, ziemlich sicher nicht. Hier werden ja relativ stupide alle Teiler getestet. Miller-Rabin (auch entrandomisiert) kann da aber was rausholen.



  • ok, meine version wär schneller gewesen 🙄



  • otze schrieb:

    ok, meine version wär schneller gewesen 🙄

    warum haste nicht eingeschickt?



  • bestimmt weil er dachte jester macht mit. :p


Anmelden zum Antworten