fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Ideone {
  8. public static void main(String[] args) {
  9. calc(5, 2);
  10. }
  11.  
  12. public static void calc(int n, int k) {
  13. for (int i = 1; i <= k; i++) {
  14. process(i, n, k);
  15. }
  16. }
  17.  
  18. public static void process(int startWith, int n, int k) {
  19. for (int i = 1; i <= k; i++) {
  20. processNext(startWith, i, n, k);
  21. }
  22. }
  23.  
  24. public static void processNext(int startWith, int nextWith, int n, int k) {
  25. int sum = startWith;
  26. System.out.print(startWith + " ");
  27. while (sum < n) {
  28. int step = nextWith;
  29. if (sum + step > n) {
  30. step = (sum + step) % n;
  31. }
  32. System.out.print(step + " ");
  33. sum += step;
  34. }
  35. System.out.println();
  36. }
  37. }
Success #stdin #stdout 0.09s 320512KB
stdin
Standard input is empty
stdout
1 1 1 1 1 
1 2 2 
2 1 1 1 
2 2 1