Advertisement
Guest User

code_prime_numbers_2*3*5*7

a guest
Feb 25th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.88 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. namespace WindowsFormsApp1
  4. {
  5. public partial class Form1 : Form
  6. {
  7. private Int64 Powmod(Int64 x, Int64 m)
  8. {
  9. Int64 res;
  10. Int64 rs;
  11. Int64 ptw;
  12. ptw = x % m;
  13. res = x % m;
  14. res = res * ptw % m * ptw % m;
  15. rs = x;
  16. ptw = 2;
  17. Int64 mp = 1;
  18. while (rs > 0)
  19. {
  20. if ((rs & 1) == 1)
  21. {
  22. mp = mp * ptw % m;
  23. };
  24. ptw = ptw * ptw % m;
  25. rs >>= 1;
  26. };
  27. return res - mp;
  28. }
  29. private Int64 Numberofzeros(Int64 a, Int64 o)
  30. {
  31. Int64 i = 2;
  32. Int64 j = 0;
  33. while ((i < o) && (j < 1))
  34. {
  35. if (Powmod(a, i) == 0)
  36. {
  37. j += 1;
  38. };
  39. i += 1;
  40. };
  41. return j;
  42. }
  43. private Int64 Primetesta(Int64 q)
  44. {
  45. Int64 r = 0;
  46. Int64 a = 2;
  47. while (a < q * q)
  48. {
  49. if (Powmod(a, q) == 0 && Numberofzeros(a, q) == 0)
  50. {
  51. r = 1;
  52. break;
  53. }
  54. else
  55. {
  56. a += 1;
  57. }
  58. };
  59. if (r == 1)
  60. {
  61. return q;
  62. };
  63. return 0;
  64. }
  65. private Int64 Primetestb(Int64 q)
  66. {
  67. Int64 r = 0;
  68. Int64 a = 2;
  69. while (a < q * q)
  70. {
  71. if (Powmod(a, q) == 0 && Numberofzeros(a, q) == 0)
  72. {
  73. r = 1;
  74. break;
  75. }
  76. else
  77. {
  78. a += 1;
  79. }
  80. };
  81. if (r == 1)
  82. {
  83. return a;
  84. };
  85. return 0;
  86. }
  87. public Form1()
  88. {
  89. InitializeComponent();
  90. }
  91. private void button1_Click(object sender, EventArgs e)
  92. {
  93. Int64 i;
  94. Int64 j;
  95. Int64 f;
  96. Int64 l;
  97. Int64 r;
  98. Int64 c = 0;
  99. Int64[] ax = new Int64[256];
  100. Int64[] ay = new Int64[256];
  101. i = 2;
  102. while (i < 256)
  103. {
  104. f = 0;
  105. j = 2;
  106. while (j < i)
  107. {
  108. if ((i % j) == 0)
  109. {
  110. f = 1;
  111. break;
  112. };
  113. j = j + 1;
  114. };
  115. if (f == 0)
  116. {
  117. ax[c] = Primetesta(i);
  118. ay[c] = Primetestb(i);
  119. c = c + 1;
  120. };
  121. i = i + 1;
  122. };
  123. if ((textBox1.Text != "") && (textBox2.Text != ""))
  124. {
  125. i = Convert.ToInt64(textBox1.Text);
  126. l = Convert.ToInt64(textBox2.Text);
  127. textBox1.Text = "";
  128. textBox2.Text = "";
  129. r = 1;
  130. f = i;
  131. j = 0;
  132. while (j < l)
  133. {
  134. if ((f & 1) == 1)
  135. {
  136. r = (r * (ax[j] + ay[j]));
  137. }
  138. else
  139. {
  140. r = (r * ax[j]);
  141. };
  142. f = f >> 1;
  143. j = j + 1;
  144. };
  145. textBox3.Text = Convert.ToString(r);
  146. };
  147. }
  148.  
  149. private void button2_Click(object sender, EventArgs e)
  150. {
  151. Int64 i;
  152. Int64 j;
  153. Int64 k;
  154. Int64 f;
  155. Int64 l;
  156. Int64 r;
  157. Int64 d;
  158. Int64 g;
  159. Int64 z;
  160. Int64 c = 0;
  161. Int64[] ax = new Int64[256 * 2];
  162. Int64[] ay = new Int64[256 * 2];
  163. Int64[] x = new Int64[256 * 2];
  164. i = 2;
  165. while (i < 256 * 2)
  166. {
  167. f = 0;
  168. j = 2;
  169. while (j < i)
  170. {
  171. if ((i % j) == 0)
  172. {
  173. f = 1;
  174. break;
  175. };
  176. j = j + 1;
  177. };
  178. if (f == 0)
  179. {
  180. ax[c] = Primetesta(i);
  181. ay[c] = Primetestb(i);
  182. c = c + 1;
  183. };
  184. i = i + 1;
  185. };
  186. if (textBox3.Text != "")
  187. {
  188. d = Convert.ToInt64(textBox3.Text);
  189. textBox3.Text = "";
  190. i = 0;
  191. while (i < 256 * 2)
  192. {
  193. x[i] = 0;
  194. i = i + 1;
  195. };
  196. g = 0;
  197. z = 0;
  198. r = 0;
  199. while (r == 0)
  200. {
  201. l = d;
  202. k = 2;
  203. while (l != 1)
  204. {
  205. if ((k - 1) * (k - 1) > d)
  206. {
  207. if ((d % k) == 0)
  208. {
  209. break;
  210. }
  211. else
  212. {
  213. k = d;
  214. break;
  215. };
  216. };
  217. while ((l % k) == 0)
  218. {
  219. l = l / k;
  220. };
  221. k = k + 1;
  222. };
  223. k = k - 1;
  224. i = 0;
  225. while (i < 256 * 2)
  226. {
  227. if (ax[i] == k)
  228. {
  229. break;
  230. };
  231. i = i + 1;
  232. };
  233. if (i == 256 * 2) { break; };
  234. j = 0;
  235. while ((j < ax[i + 1]) && (d % (ax[j]) == 0))
  236. {
  237. j = j + 1;
  238. };
  239. if (z == d)
  240. {
  241. g = 1;
  242. break;
  243. };
  244. z = d;
  245. f = 1;
  246. i = 0;
  247. while (ax[i] <= k)
  248. {
  249. f = f * ax[i];
  250. i = i + 1;
  251. };
  252. if ((d != 2 * f) && (d != f))
  253. {
  254. if ((d % (ax[j] + ay[j])) == 0)
  255. {
  256. r = 0;
  257. if (x[j] == 1)
  258. {
  259. g = 1;
  260. break;
  261. };
  262. x[j] = 1;
  263. d = d / (ax[j] + ay[j]);
  264. d = d * ax[j];
  265. };
  266. }
  267. else
  268. {
  269. if ((d % (ax[0] + ay[0])) == 0)
  270. {
  271. r = 0;
  272. if (x[0] == 1)
  273. {
  274. g = 1;
  275. break;
  276. };
  277. x[0] = 1;
  278. d = d / (ax[0] + ay[0]);
  279. d = d * ax[0];
  280. }
  281. else
  282. {
  283. r = 1;
  284. };
  285. };
  286. };
  287. if ((g == 0) && (i != 256 * 2))
  288. {
  289. r = 0;
  290. l = 0;
  291. while (l < i)
  292. {
  293. k = 1;
  294. j = 0;
  295. while (j < l)
  296. {
  297. k = k * 2;
  298. j = j + 1;
  299. };
  300. if (x[l] == 1)
  301. {
  302. r = r + k;
  303. };
  304. l = l + 1;
  305. };
  306. textBox1.Text = Convert.ToString(r);
  307. textBox2.Text = Convert.ToString(l);
  308. };
  309. };
  310. }
  311. }
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement