Guest User

Untitled

a guest
Sep 12th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1.     public void create_PrimNumbers(out BigInteger first, out BigInteger second)
  2.         {
  3.             Random zufall = new Random();
  4.             bool is_prim = true;
  5.  
  6.  
  7.             for (; ; )
  8.             {
  9.                 is_prim = true;
  10.                 BigInteger temp = zufall.Next(2, 100);
  11.  
  12.                 if (temp > 1)
  13.                 {
  14.                     // natürlich(BigInteger), insgesamt nur 2 natürliche Zahlen als Teiler(sich selbst und 1)
  15.                     // prim > 1
  16.                     for (BigInteger i = 2; i < temp; i++)
  17.                     {
  18.                         if (temp % i == 0)
  19.                         {
  20.                             is_prim = false;
  21.                         }
  22.                     }
  23.  
  24.                     if (is_prim == true)
  25.                     {
  26.                         first = temp;
  27.                         break;
  28.                     }
  29.                 }
  30.             }
  31.  
  32.  
  33.             for (; ; )
  34.             {
  35.                 is_prim = true;
  36.                 BigInteger temp = zufall.Next(2, 100);
  37.  
  38.                 if (temp > 1)
  39.                 {
  40.                     // natürlich(BigInteger), insgesamt nur 2 natürliche Zahlen als Teiler(sich selbst und 1)
  41.                     // prim > 1
  42.                     for (BigInteger i = 2; i < temp; i++)
  43.                     {
  44.                         if (temp % i == 0)
  45.                         {
  46.                             is_prim = false;
  47.                         }
  48.                     }
  49.  
  50.                     if (is_prim == true && first != temp)
  51.                     {
  52.                         second = temp;
  53.                         break;
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.  
  59.  
  60.         public bool check_relativelyPrime(BigInteger zahlA, BigInteger zahlB)
  61.         {
  62.             bool relativePrime = true;
  63.             BigInteger index = zahlA;
  64.  
  65.             // Check which one is greater and set tiniest as index
  66.  
  67.             /* if (zahlA > zahlB)
  68.             {
  69.                 index = zahlB;
  70.             } Rechenzeit Ersparnis, da Parameter schon in richtiger Reihenfolge reinkommen */
  71.  
  72.  
  73.             // Check for every number until index
  74.             // if there is a number which divides both naturally
  75.             for (BigInteger i = 2; i <= index; i++)
  76.             {
  77.                 if ((zahlA % i == 0) && (zahlB % i == 0))
  78.                 {
  79.                     relativePrime = false;
  80.                     break;
  81.                 }
  82.             }
  83.  
  84.             return relativePrime;
  85.         }
Advertisement
Add Comment
Please, Sign In to add comment