fork(1) download
  1. class Ideone
  2. {
  3. public static void main (String[] args)
  4. {
  5. int n = 5, m = 3;
  6. for (int i = 0; i < 2*(m+n); i++)
  7. {
  8. int x1 = i/(m+2*n),
  9. x2 = (i%(m+n))%n,
  10. x3 = (int)Math.ceil(((m+i)%(m+n)) / m / (1.0*n));
  11.  
  12. System.out.print(x1*(n-1) + x2 * x3 + " ");
  13.  
  14. int y1 = i/(m+n) - i/(m+2*n),
  15. y2 = x2,
  16. y3 = (int)Math.ceil((i%(m+n)) / n / (1.0*m));
  17.  
  18. System.out.println(y1*(m-1) + y2 * y3);
  19. }
  20. }
  21. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
0 0
1 0
2 0
3 0
4 0
0 0
0 1
0 2
0 2
1 2
2 2
3 2
4 2
4 0
4 1
4 2