Click
Here to go back to the homepage.
Star Arrangements Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Kattis {
private static int ball = 1;
public static void main(String[] args) throws Exception{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int stars = Integer.parseInt(reader.readLine());
StringBuilder sb = new StringBuilder(stars+":\n");
for(int firstRow = 2; firstRow <= (stars/2) +1; firstRow++){
int remainder = stars%(2 * firstRow -1);
if(remainder == 0 || remainder - firstRow == 0)
sb.append(firstRow + "," + (firstRow-1) + "\n");
remainder = stars % firstRow;
if(remainder == 0)
sb.append(firstRow + "," + firstRow + "\n");
}
System.out.print(sb);
}
}