Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //How to find linear combinations.
- // Given 'result', 'm' and 'n', find 'a' and 'b' such that the following expression is true.
- // result = m*a + n*b.
- void foo(int m, int n, int result, int low, int high)
- {
- List<Integer> aList = new ArrayList<Integer>();
- List<Integer> bList = new ArrayList<Integer>();
- for(int i = low; i < high; i++)
- {
- aList.add(m*i);
- bList.add(n*i);
- }
- for(Integer ia : aList)
- {
- for(Integer ib : bList)
- {
- if((ia+ib) == result)
- {
- System.out.println("pair found: (" + ia + ", "+ ib + ")");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement