Guest User

Untitled

a guest
Jan 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. For n=9,
  2.  
  3. 0 1 2
  4. 3 4 5
  5. 6 7 8
  6.  
  7. For n=6,
  8.  
  9. Either,
  10. 0 1 2
  11. 3 4 5
  12. or
  13. 0 1
  14. 2 3
  15. 4 5
  16.  
  17. int rowlen = (sqrt(n))
  18. int collen = (n/rowlen)
  19. int no = 0;
  20.  
  21. for (int i = 0; i < rowlen-1) {
  22. for (int j = 0; j < collen-1) {
  23.  
  24. System.out.print(no+"t")
  25. no++;
  26.  
  27. }
  28.  
  29. System.out.println()
  30. }
  31.  
  32. var n = 10;
  33.  
  34. var cols = 0;
  35.  
  36. for(var i=0; i<n; i++) {
  37. if(i>1 && ((cols === 0 && n%i === 0) || (cols>0 && i%cols===0))) {
  38. if(cols===0) { // we've found our first prime factor;
  39. // this value will be used as the number of columns
  40. cols = i;
  41. }
  42. print("n");
  43. }
  44. print(i);
  45. }
Add Comment
Please, Sign In to add comment