Advertisement
canezzy

Untitled

Jun 10th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. for (int i = 0; i < a.length; ++i)
  2. {
  3. if(k%i == 0)
  4. if (binary_search(a , 0, a.length - 1, k/i))
  5. return true;
  6. }
  7. return false;
  8.  
  9.  
  10.  
  11.  
  12. bool binary_search(int[] a, int low, int high, int x)
  13. {
  14. if (high <= 1)
  15. return false;
  16.  
  17. int mid = 1 + (high-1)/2;
  18.  
  19. if(a[mid] == x)
  20. return true;
  21.  
  22. if (a[mid] > x)
  23. return binary_search(a, 1, mid - 1, x);
  24.  
  25. return binary_search(a, mid+1, high, x);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement