Guest User

Untitled

a guest
Feb 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public static int greatest(int x, int y, int n){
  2.  
  3.  
  4. for(int i = n; i > 0; i--) {
  5. n -= 1;
  6.  
  7. if (n % x == 0 && n % y == 0){
  8. break;
  9. }
  10. }
  11. return n;
  12. }
  13.  
  14. public static int smallest(int x, int y, int n){
  15.  
  16.  
  17. for(int i = 0; i < n*n; i++) {
  18. n += 1;
  19.  
  20. if (n % x == 0 && n % y == 0){
  21. break;
  22. }
  23. }
  24. return n;
  25. }
  26.  
  27. public static BigInteger greatest(BigInteger x, BigInteger y, BigInteger n){
  28.  
  29. for(BigInteger i = n; i.compareTo(BigInteger.ONE) == 0; i.subtract(BigInteger.ONE)) {
  30. n = n.subtract(BigInteger.ONE);
  31.  
  32. if (n.mod(x) == BigInteger.ZERO && n.mod(y) == BigInteger.ZERO){
  33. break;
  34. }
  35. }
  36. return n;
  37.  
  38. public static BigInteger smallest(BigInteger x, BigInteger y, BigInteger n){
  39.  
  40. for(BigInteger i = BigInteger.ZERO; i.equals(n.multiply(n)); i = i.add(BigInteger.ONE)) {
  41. n = n.add(BigInteger.ONE);
  42.  
  43. if (n.mod(x) == BigInteger.ZERO && n.mod(y) == BigInteger.ZERO){
  44. break;
  45. }
  46. }
  47. return n;
  48. }
  49.  
  50. for(BigInteger i = n; i.compareTo(BigInteger.ZERO) == 1; i.subtract(BigInteger.ONE)) {
  51. ...
  52. }
Add Comment
Please, Sign In to add comment