fork(6) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5.  
  6. public static int sqr (int val)
  7. {
  8. int mask = 1;
  9. int factorsum = val;
  10. int sum = 0;
  11. while (val >= mask)
  12. {
  13. if ((val & mask) == mask)
  14. {
  15. sum += factorsum;
  16. }
  17. factorsum += factorsum;
  18. mask += mask;
  19. }
  20. return sum;
  21. }
  22.  
  23. public static void Main()
  24. {
  25. for (int i = 0; i < 10; i++)
  26. {
  27. Console.WriteLine("{0} -> {1}", i, sqr(i));
  28. }
  29. }
  30. }
Success #stdin #stdout 0.03s 33872KB
stdin
Standard input is empty
stdout
0 -> 0
1 -> 1
2 -> 4
3 -> 9
4 -> 16
5 -> 25
6 -> 36
7 -> 49
8 -> 64
9 -> 81