Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ChineseRemainderTheorem {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the a , b , n in equation ax=b(modn)");
- int a = sc.nextInt();
- int b = sc.nextInt();
- int n = sc.nextInt();
- System.out.println("Equation : " + a + "x=" + b + "(mod" + n + ")");
- int i = 1;
- while (true) {
- if ((a * i - b) % n == 0)
- break;
- i++;
- }
- System.out.println("The value of x is : " + i);
- }
- }
- /*
- Enter the a , b , n in equation ax=b(modn)
- 314
- 271
- 1111
- Equation : 314x=271(mod1111)
- The value of x is : 245
- */
Advertisement
Add Comment
Please, Sign In to add comment