Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int greatest(int x, int y, int n){
- for(int i = n; i > 0; i--) {
- n -= 1;
- if (n % x == 0 && n % y == 0){
- break;
- }
- }
- return n;
- }
- public static int smallest(int x, int y, int n){
- for(int i = 0; i < n*n; i++) {
- n += 1;
- if (n % x == 0 && n % y == 0){
- break;
- }
- }
- return n;
- }
- public static BigInteger greatest(BigInteger x, BigInteger y, BigInteger n){
- for(BigInteger i = n; i.compareTo(BigInteger.ONE) == 0; i.subtract(BigInteger.ONE)) {
- n = n.subtract(BigInteger.ONE);
- if (n.mod(x) == BigInteger.ZERO && n.mod(y) == BigInteger.ZERO){
- break;
- }
- }
- return n;
- public static BigInteger smallest(BigInteger x, BigInteger y, BigInteger n){
- for(BigInteger i = BigInteger.ZERO; i.equals(n.multiply(n)); i = i.add(BigInteger.ONE)) {
- n = n.add(BigInteger.ONE);
- if (n.mod(x) == BigInteger.ZERO && n.mod(y) == BigInteger.ZERO){
- break;
- }
- }
- return n;
- }
- for(BigInteger i = n; i.compareTo(BigInteger.ZERO) == 1; i.subtract(BigInteger.ONE)) {
- ...
- }
Add Comment
Please, Sign In to add comment