-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
79 lines (68 loc) · 2.59 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.ComponentModel;
using System.Diagnostics;
namespace Miller_Rabin_Test
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
Number.PreviewTextInput += Service.NumberField_PreviewTextInput;
Rounds.PreviewTextInput += Service.NumberField_PreviewTextInput;
DataObject.AddPastingHandler(Number, Service.NumberField_Pasting);
DataObject.AddPastingHandler(Rounds, Service.NumberField_Pasting);
Rounds.Text = "5";
Status.Text = "Ожидание...";
}
public async void SetStatus(String text)
{
Status.Text = text;
await Task.Delay(1);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
if (Rounds.Text.Length == 0)
{
throw new Exception("Неверное число раундов");
}
if (Number.Text.Length == 0) {
throw new Exception("Неверное число для проверки");
}
BigInteger num = BigInteger.Parse(Number.Text);
if (num < 2)
{
throw new Exception("Неверное число для проверки");
}
int rounds = Int32.Parse(Rounds.Text);
SetStatus("Вычисление...");
bool result = num.MillerRabin(rounds);
Debug.WriteLine(1 - Math.Pow(4, -rounds));
Status.Text = result ? "Число простое с вероятностью " + Math.Truncate( (1 - Math.Pow(4, -rounds)) * 100) +"%" : "Число составное";
}catch(Exception ex) {
MessageBox.Show(this, ex.Message.Length > 0 ? ex.Message : "Проверьте правильность данных", "Ошибка");
return;
}
}
}
}