Advertisement
Opteronic

cs loop j Pyramids - StringBuilder

Mar 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. public class Pyramids
  5. {
  6.     public static void Main()
  7.     {
  8.         long n = 15;//long.Parse(Console.ReadLine());//   299; //
  9.         StringBuilder builder = new StringBuilder();
  10.         long c = 0;
  11.         long i = 1;
  12.         for (; i <= n; i++)
  13.         {
  14.             c = c + i;
  15.             if (c > n)
  16.                 break;
  17.             builder.Append("1 ");
  18.             Console.WriteLine(builder.ToString());
  19.         }
  20.         Console.WriteLine(i - 1);
  21.         //Console.WriteLine(c);
  22.         Console.ReadKey();
  23.     }
  24. }
  25. /*
  26. Coki went to Egypt once. Since then he loves pyramids. As all of us know, Coki also loves numbers...
  27. Sooooo, the expected result is that Coki wants to make pyramids of blocks with numbers!
  28. You have N blocks. With these blocks you should form pyramids.
  29. Each pyramid is actually a right-angled, isosceles triangle with one cathetus on the surface (see example). Also, you can think of the triangle as a set of columns, where the leftmost is 1 and the rightmost is the highest. The Kth column has exactly K blocks on top one another.
  30. Your task is to find the total number of full columns, given a total of N blocks
  31. Input
  32. Read from the standard input
  33. On the single line, find the number N
  34. Output
  35. Print to the standard output
  36. Print the number of full columns for N
  37. Constraints
  38. 1 <= N <= 2^50^
  39. Sample tests
  40. Input
  41. Copy
  42. 5
  43. Output
  44. Copy
  45. 2
  46. Explanation
  47. Copy
  48. o
  49. o o
  50. o o
  51. Input
  52. Copy
  53. 8
  54. Output
  55. Copy
  56. 3
  57. Explanation
  58. Copy
  59. o
  60. o o
  61. o o
  62. o o o
  63. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement