Advertisement
Guest User

SomethingBroken

a guest
Feb 17th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | None | 0 0
  1. using System.Numerics;
  2. using System.Threading;
  3.  
  4. namespace StrangeThing
  5. {
  6.     class GCD3
  7.     {
  8.         class Num
  9.         {
  10.             public BigInteger v;
  11.             public Num(BigInteger a)
  12.             {
  13.                 v = a;
  14.             }
  15.  
  16.             public override string ToString()
  17.             {
  18.                 return v.ToString();
  19.             }
  20.         }
  21.  
  22.         private Num A, B, C;
  23.         public readonly BigInteger result;
  24.  
  25.         public GCD3(BigInteger a, BigInteger b, BigInteger c)
  26.         {
  27.             A = new Num(a);
  28.             B = new Num(b);
  29.             C = new Num(c);
  30.  
  31.             var t1 = new Thread(() =>
  32.                 {
  33.                     while (true)
  34.                     {
  35.                         var x = A;
  36.                         var y = B;
  37.                         if (x.v == 0 || y.v == 0 || x.v == y.v)
  38.                         {
  39.                             break;
  40.                         }
  41.                         if (x.v < y.v)
  42.                         {
  43.                             B = new Num(y.v % x.v);
  44.                         }
  45.                         else
  46.                         {
  47.                             A = new Num(x.v % y.v);
  48.                         }
  49.                     }
  50.                 });
  51.             var t2 = new Thread(() =>
  52.             {
  53.                 while (true)
  54.                 {
  55.                     var y = B;
  56.                     var z = C;
  57.                     if (y.v == 0 || z.v == 0 || y.v == z.v)
  58.                     {
  59.                         break;
  60.                     }
  61.                     if (y.v < z.v)
  62.                     {
  63.                         C = new Num(z.v % y.v);
  64.                     }
  65.                     else
  66.                     {
  67.                         B = new Num(y.v % z.v);
  68.                     }
  69.                 }
  70.             });
  71.             var t3 = new Thread(() =>
  72.             {
  73.                 while (true)
  74.                 {
  75.                     var x = A;
  76.                     var z = C;
  77.                     if (x.v == 0 || z.v == 0 || x.v == z.v)
  78.                     {
  79.                         break;
  80.                     }
  81.                     if (x.v < z.v)
  82.                     {
  83.                         C = new Num(z.v % x.v);
  84.                     }
  85.                     else
  86.                     {
  87.                         A = new Num(x.v % z.v);
  88.                     }
  89.                 }
  90.             });
  91.             t1.Start();
  92.             t2.Start();
  93.             t3.Start();
  94.  
  95.             t1.Join();
  96.             t2.Join();
  97.             t3.Join();
  98.  
  99.             result = BigInteger.Max(BigInteger.Max(A.v, B.v), C.v);
  100.         }
  101.     }
  102. }
  103.  
  104.  
  105. using System;
  106.  
  107. namespace StrangeThing
  108. {
  109.     class Program
  110.     {
  111.         static void Main()
  112.         {
  113.             Console.WriteLine("Hello");
  114.             //Console.WriteLine(new GCD3(5, 100, 20).result);
  115.  
  116.             Console.ReadKey();
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement