Skip to content

Instantly share code, notes, and snippets.

@getsadzeg
Last active March 28, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getsadzeg/a3ae27a4a5535e86bb7e18808b7e552f to your computer and use it in GitHub Desktop.
Save getsadzeg/a3ae27a4a5535e86bb7e18808b7e552f to your computer and use it in GitHub Desktop.
GEOI2017, #1
package main;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Rectangle {
public static void main(String[] args) {
Map map = new HashMap<>();
int n = 5;
int counter = 0;
if(n>0) {
for(int x=1; x<n/2; x++) {
if(doesDivide(x, n) && !map.containsValue(x)) {
counter++;
System.out.println("sizes: " + x + " " + getY(x,n)); //not necessary to print this
map.put(x, getY(x,n));
}
}
}
System.out.println(counter);
}
public static boolean doesDivide(int x, int n) {
return (n-x)%(1+2*x) == 0;
}
public static int getY(int x, int n) {
int y = 0;
if(doesDivide(x, n)) y = (n-x)/(1+2*x);
return y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment