Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- private Int64 Powmod(Int64 x, Int64 m)
- {
- Int64 res;
- Int64 rs;
- Int64 ptw;
- ptw = x % m;
- res = x % m;
- res = res * ptw % m * ptw % m;
- rs = x;
- ptw = 2;
- Int64 mp = 1;
- while (rs > 0)
- {
- if ((rs & 1) == 1)
- {
- mp = mp * ptw % m;
- };
- ptw = ptw * ptw % m;
- rs >>= 1;
- };
- return res - mp;
- }
- private Int64 Numberofzeros(Int64 a, Int64 o)
- {
- Int64 i = 2;
- Int64 j = 0;
- while ((i < o) && (j < 1))
- {
- if (Powmod(a, i) == 0)
- {
- j += 1;
- };
- i += 1;
- };
- return j;
- }
- private Int64 Primetesta(Int64 q)
- {
- Int64 r = 0;
- Int64 a = 2;
- while (a < q * q)
- {
- if (Powmod(a, q) == 0 && Numberofzeros(a, q) == 0)
- {
- r = 1;
- break;
- }
- else
- {
- a += 1;
- }
- };
- if (r == 1)
- {
- return q;
- };
- return 0;
- }
- private Int64 Primetestb(Int64 q)
- {
- Int64 r = 0;
- Int64 a = 2;
- while (a < q * q)
- {
- if (Powmod(a, q) == 0 && Numberofzeros(a, q) == 0)
- {
- r = 1;
- break;
- }
- else
- {
- a += 1;
- }
- };
- if (r == 1)
- {
- return a;
- };
- return 0;
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Int64 i;
- Int64 j;
- Int64 f;
- Int64 l;
- Int64 r;
- Int64 c = 0;
- Int64[] ax = new Int64[256];
- Int64[] ay = new Int64[256];
- i = 2;
- while (i < 256)
- {
- f = 0;
- j = 2;
- while (j < i)
- {
- if ((i % j) == 0)
- {
- f = 1;
- break;
- };
- j = j + 1;
- };
- if (f == 0)
- {
- ax[c] = Primetesta(i);
- ay[c] = Primetestb(i);
- c = c + 1;
- };
- i = i + 1;
- };
- if ((textBox1.Text != "") && (textBox2.Text != ""))
- {
- i = Convert.ToInt64(textBox1.Text);
- l = Convert.ToInt64(textBox2.Text);
- textBox1.Text = "";
- textBox2.Text = "";
- r = 1;
- f = i;
- j = 0;
- while (j < l)
- {
- if ((f & 1) == 1)
- {
- r = (r * (ax[j] + ay[j]));
- }
- else
- {
- r = (r * ax[j]);
- };
- f = f >> 1;
- j = j + 1;
- };
- textBox3.Text = Convert.ToString(r);
- };
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Int64 i;
- Int64 j;
- Int64 k;
- Int64 f;
- Int64 l;
- Int64 r;
- Int64 d;
- Int64 g;
- Int64 z;
- Int64 c = 0;
- Int64[] ax = new Int64[256 * 2];
- Int64[] ay = new Int64[256 * 2];
- Int64[] x = new Int64[256 * 2];
- i = 2;
- while (i < 256 * 2)
- {
- f = 0;
- j = 2;
- while (j < i)
- {
- if ((i % j) == 0)
- {
- f = 1;
- break;
- };
- j = j + 1;
- };
- if (f == 0)
- {
- ax[c] = Primetesta(i);
- ay[c] = Primetestb(i);
- c = c + 1;
- };
- i = i + 1;
- };
- if (textBox3.Text != "")
- {
- d = Convert.ToInt64(textBox3.Text);
- textBox3.Text = "";
- i = 0;
- while (i < 256 * 2)
- {
- x[i] = 0;
- i = i + 1;
- };
- g = 0;
- z = 0;
- r = 0;
- while (r == 0)
- {
- l = d;
- k = 2;
- while (l != 1)
- {
- if ((k - 1) * (k - 1) > d)
- {
- if ((d % k) == 0)
- {
- break;
- }
- else
- {
- k = d;
- break;
- };
- };
- while ((l % k) == 0)
- {
- l = l / k;
- };
- k = k + 1;
- };
- k = k - 1;
- i = 0;
- while (i < 256 * 2)
- {
- if (ax[i] == k)
- {
- break;
- };
- i = i + 1;
- };
- if (i == 256 * 2) { break; };
- j = 0;
- while ((j < ax[i + 1]) && (d % (ax[j]) == 0))
- {
- j = j + 1;
- };
- if (z == d)
- {
- g = 1;
- break;
- };
- z = d;
- f = 1;
- i = 0;
- while (ax[i] <= k)
- {
- f = f * ax[i];
- i = i + 1;
- };
- if ((d != 2 * f) && (d != f))
- {
- if ((d % (ax[j] + ay[j])) == 0)
- {
- r = 0;
- if (x[j] == 1)
- {
- g = 1;
- break;
- };
- x[j] = 1;
- d = d / (ax[j] + ay[j]);
- d = d * ax[j];
- };
- }
- else
- {
- if ((d % (ax[0] + ay[0])) == 0)
- {
- r = 0;
- if (x[0] == 1)
- {
- g = 1;
- break;
- };
- x[0] = 1;
- d = d / (ax[0] + ay[0]);
- d = d * ax[0];
- }
- else
- {
- r = 1;
- };
- };
- };
- if ((g == 0) && (i != 256 * 2))
- {
- r = 0;
- l = 0;
- while (l < i)
- {
- k = 1;
- j = 0;
- while (j < l)
- {
- k = k * 2;
- j = j + 1;
- };
- if (x[l] == 1)
- {
- r = r + k;
- };
- l = l + 1;
- };
- textBox1.Text = Convert.ToString(r);
- textBox2.Text = Convert.ToString(l);
- };
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement