Click here to Skip to main content
13,150,622 members (37,583 online)
Click here to Skip to main content

Tagged as

Stats

45.6K views
498 downloads
14 bookmarked
Posted 23 Sep 2008

Chinese Remainder Problem

, 17 Oct 2008
Solve the Chinese remainder problem cleverly
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ChineseRemainderProblem
{
    public partial class FormRemainderProblem : Form
    {
        public FormRemainderProblem()
        {
            InitializeComponent();
        }

        private void buttonSolve_Click(object sender, EventArgs e)
        {
            try
            {
                int a = int.Parse(textBoxA.Text);
                int b = int.Parse(textBoxB.Text);
                int c = int.Parse(textBoxC.Text);
                int r1 = int.Parse(textBox1.Text);
                int r2 = int.Parse(textBox2.Text);
                int r3 = int.Parse(textBox3.Text);

                int n0, t;
                RemainderProblem.Solve(a, b, c, r1, r2, r3, out n0, out t);

                textBoxN.Text = n0.ToString();
                textBoxT.Text = t.ToString();

                listBoxN.Items.Clear();
                for (int i = 0; i < 20; i++)
                {
                    listBoxN.Items.Add(n0 + t * i);
                }
                listBoxN.Items.Add("...");
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message, "No solution");
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Liu Junfeng
Architect YunCheDa Hangzhou
China China
No Biography provided

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170924.2 | Last Updated 17 Oct 2008
Article Copyright 2008 by Liu Junfeng
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid