Example #1
0
 private void Jacobia_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter && IsNumber(Jacobia.Text))
     {
         Jacobib.Focus();
     }
 }
Example #2
0
 private void Jacobicount_Click(object sender, EventArgs e)
 {
     Jacobia.Focus();
     if (Jacobicheck())
     {
         moveresult();
         printresult.Text = "a=" + Jacobia.Text + "\nb=" + Jacobib.Text;
         long a = Convert.ToInt64(Jacobia.Text), b = Convert.ToInt64(Jacobib.Text);
         int  result = 1;
         if (mygcd(a, b) != 1 || a == 0)
         {
             result = 0;
         }
         else
         {
             int  count = 0;
             long mod;
             while (a != 1)
             {
                 if (a >= b)//先讓a的值保證小於b
                 {
                     a %= b;
                 }
                 else if (a % 2 == 0)//此時若a是二的倍數,則把二提乾淨
                 {
                     count = 0;
                     do//統計能提幾個2
                     {
                         if (a % 2 == 0)
                         {
                             ++count;
                             a /= 2;
                         }
                     } while (a % 2 == 0);
                     if (count % 2 == 1)//若有奇數個,考慮變號
                     {
                         mod = b % 8;
                         if (mod == 3 || mod == 5)
                         {
                             result *= -1;                      //需變號
                         }
                     }
                 }
                 else//此時保證a<b且a和b都是奇數,可倒數
                 {
                     if (a % 4 == 3 && b % 4 == 3)//若a和b(mod4)=3,則需變號
                     {
                         result *= -1;
                     }
                     change(ref a, ref b);
                 }
             }
         }
         printresult.Text += "\n a\n(-) =" + result + "\n p";
         Jacobia.Clear();
         Jacobib.Clear();
     }
 }