sandeshMC

Congruence

Apr 6th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ChineseRemainderTheorem {
  4.  
  5.     /**
  6.      * @param args
  7.      */
  8.     public static void main(String[] args) {
  9.         // TODO Auto-generated method stub
  10.         Scanner sc = new Scanner(System.in);
  11.         System.out.println("Enter the a , b , n in equation ax=b(modn)");
  12.         int a = sc.nextInt();
  13.         int b = sc.nextInt();
  14.         int n = sc.nextInt();
  15.         System.out.println("Equation : " + a + "x=" + b + "(mod" + n + ")");
  16.         int i = 1;
  17.         while (true) {
  18.             if ((a * i - b) % n == 0)
  19.                 break;
  20.             i++;
  21.         }
  22.         System.out.println("The value of x is : " + i);
  23.     }
  24.  
  25. }
  26. /*
  27. Enter the a , b , n in equation ax=b(modn)
  28. 314
  29. 271
  30. 1111
  31. Equation : 314x=271(mod1111)
  32. The value of x is : 245
  33. */
Advertisement
Add Comment
Please, Sign In to add comment