整数分解的C#代码

这段代码展示了如何使用C#实现整数分解算法。通过输入一个整数,程序会找到该数的因数。算法基于筛法和平方根简化,有效减少搜索范围。点击按钮后,将显示分解结果及其尝试次数。
摘要由CSDN通过智能技术生成
public Form1()
        {
            InitializeComponent();
            textBox1.Text = "56944483"; // 3683 14741
            textBox2.Text = "44449";
            textBox3.Text = "99991";   // find solution with 2446 try
        }
        private void button1_Click(object sender, EventArgs e)
        {
            long number = long.Parse(textBox1.Text);
            long norm = (long)Math.Sqrt(number);
            long norm2 = norm * norm;
            int count = 0;
            int[] modj2 = new int[8] { 0, 1, 4, 9, 0, 9, 4, 1 }; // mod 16
            int[] mod = new int[8];
            int[] good = new int[8];
            label1.Text = "";
            label2.Text = "";
            for (int i = 1; i < 10; i++)  // only search to sqrt(number)/3; or two factors are within 10 times of each other
            {
                bool found = false;
                norm = (long)Math.Sqrt(number / i / 4);
                norm = norm * 2;  // base is even number
                norm2 = norm * norm;
                long k = number / norm2;
                long m = (number - k * norm2) / norm;
                long p = number - k * norm2 - m * norm;
                long xmax = (long)Mat
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值