Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Go to top

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
Software Developer (Senior) Beyondsoft SH
China China
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 17 Oct 2008
Article Copyright 2008 by Liu Junfeng
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid